The Account History Example


Returning XTP from a Servlet

In the previous chapter, you learned how to use a JSP template to customize output from a servlet by dispatching to the new page. You can use the same type of technique with XTP pages as well. Consider the servlet shown in Listing 5.1.

Listing 5.1: The ViewAccount servlet.

start example
 import java.io.*; import java.sql.*; import javax.servlet.*; import javax.servlet.http.*; import javax.naming.*; import javax.sql.*; public class ViewAccount extends HttpServlet {   public void doGet(HttpServletRequest request,                     HttpServletResponse response)     throws IOException, ServletException {     ServletContext app = getServletContext();     RequestDispatcher disp =       app.getRequestDispatcher("viewAll.xtp");     disp.forward(request, response);   }   public void doPost(HttpServletRequest request,     HttpServletResponse response)     throws ServletException, IOException {     doGet(request, response);   } } 
end example

When a request is made of the ViewAccount servlet, the code automatically forwards the request to the viewAll.xtp page, just like forwarding to a JSP page. In most cases, the servlet obtains information from a database or through variables stored for use by the XTP template.




Mastering Resin
Mastering Resin
ISBN: 0471431036
EAN: 2147483647
Year: 2002
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net