Home » Archive

Articles tagged with: javaabout.com

Java Codes »

[12 Feb 2009 | No Comment | 137 views]

For example, you have two servlets (Servlet1 and Servlet2).
In Servlet1, you have a method called getString().
In Servlet2, use
ServletContext context = getServletContext();
to get servlet context of Servlet2. Then use
Servlet1 servlet = (Servlet1)context.getServlet(“Servlet1″);
to get the Servlet1 servlet object.
Now, you can Call Servlet1 method from Servlet2 with
servlet.getString();

Java Codes »

[12 Feb 2009 | No Comment | 191 views]

This J2EE tip demostrates chaining method in servlets. Servlet Chaining means the output of one servlet act as a input to another servlet. Servlet Aliasing allows us to invoke more than one servlet in sequence when the URL is opened with a common servlet alias. The output from first Servlet is sent as input to other Servlet and so on. The Output from the last Servlet is sent back to the browser. The entire process is called Servlet Chaining.
// FirstServlet
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class FirstServlet extends HttpServlet {
String name ;
ServletConfig config;