JSP Tutorials - Herong's Tutorial Examples - v5.11, by Herong Yang
Information from "request" Object
This section provides a tutorial example on how to obtain information from the 'request' implicit object provided by the JSP container.
The "request" object is an important implicit 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) 2006 HerongYang.com. All Rights Reserved. --> <html><body> <pre> Information about request: <% out.println("Class Name: "+request.getClass().getName()); out.println("Auth Type: "+request.getAuthType()); out.println("Context Path: "+request.getContextPath()); out.println("Method: "+request.getMethod()); out.println("Path Info: "+request.getPathInfo()); out.println("Path Translated: "+request.getPathTranslated()); out.println("Query String: "+request.getQueryString()); out.println("Remote User: "+request.getRemoteUser()); out.println("Session ID: "+request.getRequestedSessionId()); out.println("Request URI: "+request.getRequestURI()); out.println("Request URL: "+request.getRequestURL()); out.println("Servlet Path: "+request.getServletPath()); out.println("Cookies:"); javax.servlet.http.Cookie[] cookies = request.getCookies(); if (cookies!=null) { for (int i=0; i<cookies.length; i++) { out.println(" "+cookies[i].getName()+": " +cookies[i].getValue()); } } out.println("Headers:"); java.util.Enumeration e = request.getHeaderNames(); while (e.hasMoreElements()) { String n = (String) e.nextElement(); out.println(" "+n+": "+request.getHeader(n)); } %> </pre> </body></html>
Deploy it on the Tomcat server and visit it with a browser to see the output:
Information about request: Class Name: org.apache.catalina.connector.RequestFacade Auth Type: null Context Path: Method: GET Path Info: null Path Translated: null Query String: null Remote User: null Session ID: B543957CB66D707E234B0808A989130D Request URI: /RequestInfo.jsp Request URL: http://localhost:8080/RequestInfo.jsp Servlet Path: /RequestInfo.jsp Cookies: JSESSIONID: B543957CB66D707E234B0808A989130D Headers: host: localhost:8080 connection: keep-alive upgrade-insecure-requests: 1 user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537... accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/... accept-encoding: gzip, deflate, br accept-language: en-US,en;q=0.9 cookie: JSESSIONID=B543957CB66D707E234B0808A989130D
Table of Contents
JSP (JavaServer Pages) Overview
Tomcat Installation on Windows Systems
Information of JSP Execution Context
►Information from "request" Object
Methods Supported by the "session" Object
Syntax of JSP Pages and JSP Documents
JavaBean Objects and "useBean" Action Elements
Managing HTTP Response Header Lines
Non-ASCII Characters Support in JSP Pages
Overview of JSTL (JSP Standard Tag Libraries)
Multiple Tags Working Together
Using Tomcat on CentOS Systems
Connecting to SQL Server from Servlet