Monthly Archives: July 2013

Tomcat Web Application Directory Structure

What is webapps folder in tomcat?
webapps folder is the appBase for host name localhost.
This will be configured in conf/server.xml.

eg.



            unpackWARs=”true” autoDeploy=”true”>

you can change default webapps folder by editing appBase in host tag.

Eg.



            unpackWARs=”true” autoDeploy=”true”>


What is exampleapp in the above image?
It is the name of the webapplication which is deployed in tomcat.

Here index.jsp is welcome file. This will be configured in web.xml file under WEB-INF folder.

Images/
–> this folder will contain all the images are used in this application.

META-INF/
This is optional folder.
Tomcat uses the Context configuration element to contain information about components required by a given application, such as databases, realms, or custom loaders.  Additionally, the Context element can be configured with a wide variety of attributes that control things such as loggingreload permissions, caching, and more.

WEB-INF/
This folder will not be visible to the end user.
This folder contains jar files (libs), java compiled codes(class files), properties files, xml’s and logs. 

Classes/
–> this folder will have compiled codes of java files. 
Which will contain Java, Servlets, Filter , Struts, Hibernates (All java and j2ee codes ).. etc

web.xml
This is the configuration file of web application.
Here Servlet, filter, web service mapping will be done with initial values.

How to install Balsamiq Mockups in Ubuntu?

Step 1 :

Copy the following code in a text file and save it as executable file. that is with .sh extension.
eg. balsamiq-installer.sh

#!/usr/bin/env bash
if [ $EUID != 0 ]; then
    “This script must be run with sudo”
    exit $?
fi

echo ”  Installing dependencies”
apt-get install ia32-libs -y # Note: This dep is a bit overkill but it’s useful anyway
ln -s /usr/lib/i386-linux-gnu/libgnome-keyring.so.0 /usr/lib/libgnome-keyring.so.0

echo ”  Downloading installers”
wget -P /tmp/ http://airdownload.adobe.com/air/lin/download/2.6/AdobeAIRInstaller.bin
wget -P /tmp/ http://builds.balsamiq.com/b/mockups-desktop/MockupsForDesktop32bit.deb

echo ”  Installing AIR”
chmod +x /tmp/AdobeAIRInstaller.bin
/tmp/AdobeAIRInstaller.bin -silent -eulaAccepted
echo ”  Installing Balsamiq”
dpkg -i /tmp/MockupsForDesktop32bit.deb

Step 2 :
Give chmod 777 permission to the file.

*** For 64 bit machine, change the mockup deb file name from 32 to 64.

JavaScript call() vs apply()

call() and apply() method are Function class’s core functions.

exaple 1 :-

function Product(name, price) {
    this.name = name;
    this.price = price;

    if (price < 0)
        throw RangeError(‘Cannot create product “‘ + name + ‘” with a negative price’);
    return this;
}

function Food(name, price) {
    Product.call(this, arguments);
    this.category = ‘food’;
}
Food.prototype = new Product();

function Toy(name, price) {
    Product.apply(this, arguments);
    this.category = ‘toy’;
}
Toy.prototype = new Product();

var cheese = new Food(‘feta’, 5);
var fun = new Toy(‘robot’, 40);

console.log(JSON.stringify(cheese));
console.log(JSON.stringify(fun));

exaple 2 :-

function theFunction(name, profession) {
    alert(“My name is ” + name + ” and I am a ” + profession + “.”);
}

theFunction(“John”, “fireman”);
theFunction.apply(undefined, [“Susan”, “school teacher”]);
theFunction.call(undefined, “Claude”, “mathematician”);

call() :-
1. Any no of arguments to the function.
2. it will get parameters as like arguments to be passed to the function.

eg. functionName.call( this, a, b);
    . this will be the scope of the function.
    . u ll get function(a,b);

eg. functionName.call( this, array/string);
    . this will be the scope of the function.
    . u ll get function([a],b);

apply() :-
1. only two arguments to the function.
2. It ill get no of args based on the array lenth.

ie. functionName.call( this, arguments);
ie. functionName.call( this, array);

eg. functionName.call( this, [‘a’,’b’);
    . this will be the scope of the function.
    . u ll get function(a,b);

Reading Xml files in javascript using Ajax.

function XMLLoader (name, xmlPath){

            var xmlData;
            this.name = name;
            this.xmlPath = xmlPath;

            var that = this;
            $.ajax({
                type: “GET”,
                url: this.xmlPath,
                dataType: “xml”,
                async: false,
                success: function(xml){
                    if (jQuery.browser.msie) {
                        var xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
                        xmlDoc.loadXML(xml);
                        xml = xmlDoc;
                    }

                   xmlData = $(xml);
                }
            });

            return xmlData;
        }