Servlet Chaining is the process of chaining the output of one Servlet to another Servlet.
You need to configure your servlet engine Java Web server, JRun, , JServ ... for this process to work.
For example to configure JRun for servlet chaining,
Select the JSE service (JRun servlet engine) to access to the JSE Service Config panel. You have just to define a new mapping rule where you define your chaining servlet.
Let's say /servlets/TicketChainServlet for the virtual path and a comma separated list of servlets as CustomerServlet ,TicketServlet.
So when you invoke a request like http://javacommerce.com/servlets/chainServlet, internally the servlet CustomerServlet will be invoked first and its results will be piped into the servlet TicketServlet.
The CustomerServlet servlet code should look like:
public class CustomerServletextends HttpServlet {
public void doGet (HttpServletRequest request, HttpServletResponseresponse) {
PrintWriter out =res.getWriter();
rest.setContentType("text/html");
...
out.println("Customer Name : Tom");
}
}
TicketServlet has to do is to open an inputstream to the request object and read the data into a BufferedReader object.
BufferedReader b = newBufferedReader( new InputStreamReader(req.getInputStream() ) );
String data = b.readLine();
b.close();
Here in data variable you would get "CustomerName : Tom"
Note : Not many Servlet Engines support ServletChaining. Also it has been removed from the standard specifications for Servlets.
Wednesday, August 12, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment