|
Execution Context
Part:
1
2
(Continued from previous part...)
Output:
JSP Page Context Information
Pre-defined objects:
out: org.apache.jasper.runtime.JspWriterImpl
this: org.apache.jsp.ContextInfo_jsp
request: org.apache.coyote.tomcat4.CoyoteRequestFacade
response: org.apache.coyote.tomcat4.CoyoteResponseFacade
session: org.apache.catalina.session.StandardSessionFacade
application: org.apache.catalina.core.ApplicationContextFacade
config: org.apache.catalina.core.StandardWrapperFacade
pageContext: org.apache.jasper.runtime.PageContextImpl
Information about session:
= pageContext.getSession();
Class Name: org.apache.catalina.session.StandardSessionFacade
Session ID: 35466D59BF54A551BFBABA22B61A66EB
Create Time: Sun Dec 22 13:40:55 EST 2002
Last Access Time: Sun Dec 22 13:40:55 EST 2002
Is Session New: true
Information about sessionContext:
= session.getSessionContext();
Class name: org.apache.catalina.session.StandardSessionContext
Information about application:
= pageContext.getServletContext();
Class Name: org.apache.catalina.core.ApplicationContextFacade
Major Version: 2
Minor Version: 3
Server Info: Apache Tomcat/4.1.18
Serlet Context Name: Welcome to Tomcat
A new session will be established, if this JSP page is requested for the first time.
Subsequent requests will share the same session. Click the refresh button on the
Web browser, you will see that the session ID will be the same, the create time will be
the same, but the last access time will be the new time, and "is session new" will
be "false".
The "request" Object
The "request" object is an important object to the JSP page, because it contains
a lot of useful information. The following JSP page will you some details of
the "request" object:
<!--
- RequestInfo.jsp
- Copyright (c) 2002 by Dr. Herong Yang. All rights reserved.
-->
<html><body>
<p>
<b>Information about request:</b><br/>
<%
out.println("Class Name: "+request.getClass().getName()+"<br/>");
out.println("Auth Type: "+request.getAuthType()+"<br/>");
out.println("Context Path: "+request.getContextPath()+"<br/>");
out.println("Method: "+request.getMethod()+"<br/>");
out.println("Path Info: "+request.getPathInfo()+"<br/>");
out.println("Path Translated: "+request.getPathTranslated()+"<br/>");
out.println("Query String: "+request.getQueryString()+"<br/>");
out.println("Remote User: "+request.getRemoteUser()+"<br/>");
out.println("Requested Session ID: "+request.getRequestedSessionId()
+"<br/>");
out.println("Request URI: "+request.getRequestURI()+"<br/>");
out.println("Request URL: "+request.getRequestURL()+"<br/>");
out.println("Servlet Path: "+request.getServletPath()+"<br/>");
out.println("Cookies:<br/>");
javax.servlet.http.Cookie[] cookies = request.getCookies();
for (int i=0; i<cookies.length; i++) {
out.println(" "+cookies[i].getName()+": "
+cookies[i].getValue()+"<br/>");
}
out.println("Headers:<br/>");
java.util.Enumeration e = request.getHeaderNames();
while (e.hasMoreElements()) {
String n = (String) e.nextElement();
out.println(" "+n+": "+request.getHeader(n)+"<br/>");
}
%>
</p>
</body></html>
Output:
Information about request:
Class Name: org.apache.coyote.tomcat4.CoyoteRequestFacade
Auth Type: null
Context Path:
Method: GET
Path Info: null
Path Translated: null
Query String: null
Remote User: null
Requested Session ID: 13190484CD4CE195C9434A318D46950E
Request URI: /RequestInfo.jsp
Request URL: http://localhost:8080/RequestInfo.jsp
Servlet Path: /RequestInfo.jsp
Cookies:
JSESSIONID: 13190484CD4CE195C9434A318D46950E
Headers:
accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, ...
accept-language: en-us
accept-encoding: gzip, deflate
user-agent: Mozilla/4.0 (compatible; MSIE 6.0; MSNIA; Windows NT ...
host: localhost:8080
connection: Keep-Alive
cookie: JSESSIONID=13190484CD4CE195C9434A318D46950E
The "session" Object
session: A object provided by the JSP server to hold information and methods
common to all JSP pages running under one session. The session object must be an instance
of a class that implements the javax.servlet.http.HttpSession interface defined by the J2EE
specification. Here is the highlights of the HttpSession interface defined in J2EE 1.3:
- getAttribute(): Returns the object that is associated to the specified key string.
defined in the session.
- getAttributeNames(): Returns an Enumeration object that contains all the key strings
defined in the session.
- getCreationTime(): Returns the time when this session was created, measured
in milliseconds since midnight January 1, 1970 GMT.
- getId(): Returns the session ID as a string.
- setAttribute(): Associate an object with the specified key string and store them
to this session.
More information about the session object and sample JSP codes will be give in another chapter.
Part:
1
2
|