Friday, 27 February 2015

Differences Between Forwarding and Redirection

Forwarding
Redirection
While forwarding, there is no intimation given back to the client.
While redirecting, there will be an intimation given back to the client.
Only one pair of request and response objects are created.
Minimum two pairs of request and response objects are created by the container.
Automatically the data is also forwarded.
Only control is redirected, but data is not transferred.
Forwarding is only possible within the server only.
Redirecting is possible within the server and across the servers.
The destination resource must be java enabled resource.
The destination resource may be java enabled resource (or) it can be non-java enabled resource.

Is it possible to read the data of a web application from another web application ?

Yes. 
It possible by using the getContext() method. It gives ServletContext object of that web application into our current web application.
            ServletContext ctx = getServletContext();

            ServletContext ctx2 = ctx.getContext(“webapp_name”);

Monday, 16 February 2015

Can we create a userdefined immutable class?

     Yes. 
         i)     Make the class as final and
         ii)   make the data members as private and final.

Program:
final class Test{
private int i;
Test(int i){
this.i=i;
}
public Test modify(int i){
if(this.i==i){
return this;
return(new Test(i))
}
}
public static void main(String args[] ){
Test t1= new Test(10);
Test t2= t1.modify(10)
Test t3= new Test(10);
Test t4=t1.modify(100);
System.out.println(t1==t2);    //true
System.out.println(t1==t4);//false
System.out.println(t1==t3)//true
}
}

Wednesday, 4 February 2015

Xpath Expressions

XPath uses path expressions to select nodes or node-sets in an XML document.

In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document nodes.

XML documents are treated as trees of nodes. The topmost element of the tree is called the root element.

/ -->Selects from the root node

// -->Selects nodes in the document from the current node that match the selection               no matter where they are

. -->Selects the current node

.. -->Selects the parent of the current node

@ -->Selects attributes