|
Execution Context
Part:
1
2
Predefined Objects
Now we know that the Java statements embedded in JSP pages will translated into
_jspService() method of a special Servlet class. In that method, there are
a couple of pre-defined objects ready for the embedded Java statements:
- out: The output stream to collect dynamic data to be mixed into the final Web
document.
- this: The instance of the special Servlet class.
- request: An HttpServletRequest object representing the request received from
the Web browser.
- response: An HttpServletResponse object representing the response to be delivered
back to the Web browser.
- session: An HttpSession object representing the concept of linking multiple trips
of requests and response into a single process unit.
- application: A ServletContext object representing the concept of grouping Servlets
into a single application.
- config: A ServletConfig object.
- pageContext: A PageContext object.
The following JSP page will show you more details about those pre-defined objects:
<!--
- ContextInfo.jsp
- Copyright (c) 2002 by Dr. Herong Yang. All rights reserved.
-->
<html><body>
<p>
<b>JSP Page Context Information</b><br/>
</p>
<p>
<b>Pre-defined objects:</b><br/>
<%
out.println("out: "+out.getClass().getName()+"<br/>");
out.println("this: "+this.getClass().getName()+"<br/>");
out.println("request: "+request.getClass().getName()+"<br/>");
out.println("response: "+response.getClass().getName()+"<br/>");
out.println("session: "+session.getClass().getName()+"<br/>");
out.println("application: "+application.getClass().getName()
+"<br/>");
out.println("config: "+config.getClass().getName()+"<br/>");
out.println("pageContext: "+pageContext.getClass().getName()
+"<br/>");
%>
</p>
<p>
<b>Information about session:</b><br/>
<i>= pageContext.getSession();</i><br/>
<%
out.println("Class Name: "+session.getClass().getName()+"<br/>");
out.println("Session ID: "+session.getId()+"<br/>");
java.util.Date d = new java.util.Date();
d.setTime(session.getCreationTime());
out.println("Create Time: "+d.toString()+"<br/>");
d.setTime(session.getLastAccessedTime());
out.println("Last Access Time: "+d.toString()+"<br/>");
out.println("Is Session New: "+session.isNew()+"<br/>");
%>
</p>
<p>
<b>Information about sessionContext:</b><br/>
<i>= session.getSessionContext();</i><br/>
<%
javax.servlet.http.HttpSessionContext c
= session.getSessionContext();
out.println("Class name: "+c.getClass().getName()+"<br/>");
%>
</p>
<p>
<b>Information about application:</b><br/>
<i>= pageContext.getServletContext();</i><br/>
<%
out.println("Class Name: "+application.getClass().getName()+"<br/>");
out.println("Major Version: "+application.getMajorVersion()+"<br/>");
out.println("Minor Version: "+application.getMinorVersion()+"<br/>");
out.println("Server Info: "+application.getServerInfo()+"<br/>");
out.println("Serlet Context Name: "
+application.getServletContextName()+"<br/>");
java.util.Enumeration e = application.getServletNames();
while (e.hasMoreElements()) {
String n = (String) e.nextElement();
out.println("Servlet Name: "+n+"<br/>");
}
e = application.getInitParameterNames();
while (e.hasMoreElements()) {
String n = (String) e.nextElement();
out.println("Init Parameter Name: "+n+"<br/>");
}
%>
</p>
</body></html>
(Continued on next part...)
Part:
1
2
|