1
Introduzione a Java Server Pages
Lucidi tratti da www.corewebprogramming.com
The Need for JSP
- With servlets, it is easy to
– Read form data – Read HTTP request headers – Set HTTP status codes and response headers – Use cookies and session tracking – Share data among servlets – Remember data between requests
- Much more difficult is to
– Use those println statements to generate HTML – Maintain that HTML
The JSP Framework
- Idea: Turn Code and HTML inside out
– Use regular HTML for most of page – Mark servlet code with special tags – Entire JSP page gets translated into a servlet (once), and servlet is what actually gets invoked (for each request)
- Example:
– Suppose the following JSP is in OrderConfirmation.jsp
Thanks for ordering <em><%= request.getParameter("title") %></em>
– URL
http://host/OrderConfirmation.jsp?title=Core+Web+Programmi ng
– Result: