ZengCode.Com (The Thai Php Framework)  


Home   Download   Manual   About us    

Facebook   


MAIN MENU
News
Php Tips
Android Programming
Design Pattern By PHP
C# using Linq น่าใช้จริงๆ
C# Tips & Technique
C# Design Pattern
Linux Quick Tips
Java & JavaScript Tips
Database & SQL
ZengCode Framework Guide
Zeng Code Code
Programming
IPhone (Tips and Trick)

Download เอกสารที่น่าสนใจ

     Combining JSP and Servlets  (2009-10-19)

Common approach:

  • Servlets handle the contents (using lots of Java code)
  • JSP pages handle the presentation (using lots of HTML)

- communicate using HttpSession attributes, forward requests using RequestDispatcher

Example Servlet receiving the original request:
public class Register extends HttpServlet 
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String email = request.getParameter("email");
        HttpSession session = request.getSession(true);
        session.setAttribute("email", email);
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/present.jsp");
        dispatcher.forward(request, response);
    }
}

JSP page producing the final response:
mailing list
<h1>Welcome!</h1>
You have registered the following address:
<tt><%= session.getAttribute("email") %></tt>
<p><a href="continue">Continue</a>
</body></html>

- this quickly becomes a mess...


Comment
Name
Comment
Security CodeCAPTCHA Image

easy tracking
avis car rental discount code

This page took 0.799486 seconds to load.