August 28, 2011

JSP Implicit Objects Demo

The 9 JSP implicit objects are,
  • request (HttpServletRequest)
  • response (HttpServletResponse)
  • out (JspWriter)
  • session (HttpSession)
  • config (ServletConfig)
  • application (ServletContext)
  • page (Object)
  • pageContext (PageContext)
  • exception (Throwable)
Create a JSP - ImplicitObjectsDemo.jsp - in the WebContent folder of the web application,

<html>
<head>
   <title>Implicit Objects Demo</title>
</head>
<body>
<%= "test = " + request.getParameter("test") %>

<% response.setHeader("MyHeader", "MyValue"); %>
<br/><br/>
<%= "Session Id= " + session.getId() %>
<br/><br/>
<%= "Servlet API version supported (through ServletContext): " + application.getMinorVersion() + "." + application.getMinorVersion() %>
<br/><br/>
<%= "The JSP Servlet name (through ServletConfi) " + config.getServletName() %>
<br/><br/>
<%= "JSP Servlet class name (through page) is " + page.getClass().getName() %>

</body>
</html>

Test the code with the following URL in the browser,

http://localhost:8080/WebAppName/ImplicitObjectsDemo.jsp?test=abcd

No comments:

Post a Comment