Professional Documents
Culture Documents
Java Server Pages: Problem With Servlets
Java Server Pages: Problem With Servlets
JSP JSP…
• Uses regular HTML for most of the page. • A JSP page typically consists of static
• Servlet code is marked with special tags. HTML components, special JSP tags and
• The entire JSP page gets translated into a optional snippets of code written in java
servlet (once) and for each request, it is language, known as “Scriptlets”.
the servlet which actually gets invoked. • Much easier to write and maintain.
• It is a standard extension defined on top of
servlets.
JSPs.. JSPs…
• The logic to generate dynamic content is • Two phases of operation – a translation
kept separate from the static presentation phase and a request processing phase.
by encapsulating it in external • The translation phase is carried out only
components. once (unless the JSP changes), while the
request processing phase will occur on
• Portable – can be moved across platforms every request.
and web-servers without any changes.
• The first request for the JSP results in the
• Completely leverage the servlet API. translation phase where the JSP is
converted into a servlet.
1
25-Sep-21
2
25-Sep-21
3
25-Sep-21
Loops
• Controls.jsp • Three kinds of loops normally used – The
for loop, while loop and the do-while loop.
4
25-Sep-21
Predefined variables
• request – HttpServletRequest • Loops.jsp
• response – HttpServletResponse
• out – Writer used to send output to client. • The function calls that are used in a
• session – the HttpSession associated servlet can be used within the jsp as well.
with the request
• application – the ServletContext as
obtained via getServletContext()
5
25-Sep-21
Exception Handling
• FetchSysProp.jsp and myerror.jsp