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 All Rights Reserved.
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());
   javax.servlet.http.Cookie[] cookies = request.getCookies();
   if (cookies!=null) {
      for (int i=0; i<cookies.length; i++) {
         out.println("   "+cookies[i].getName()+": "
   java.util.Enumeration e = request.getHeaderNames();
   while (e.hasMoreElements()) {
      String n = (String) e.nextElement();
      out.println("   "+n+": "+request.getHeader(n));

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
   JSESSIONID: B543957CB66D707E234B0808A989130D
   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

 About This Book

 JSP (JavaServer Pages) Overview

 Tomcat Installation on Windows Systems

 JSP Scripting Elements

 Java Servlet Introduction

JSP Implicit Objects

 What Are Implicit Objects

 Information of JSP Execution Context

Information from "request" Object

 Methods Supported by the "session" Object

 Syntax of JSP Pages and JSP Documents

 JSP Application Session

 Managing Cookies in JSP Pages

 JavaBean Objects and "useBean" Action Elements

 Managing HTTP Response Header Lines

 Non-ASCII Characters Support in JSP Pages

 Performance of JSP Pages

 EL (Expression Language)

 Overview of JSTL (JSP Standard Tag Libraries)

 JSTL Core Library

 JSP Custom Tags

 JSP Java Tag Interface

 Custom Tag Attributes

 Multiple Tags Working Together

 File Upload Test Application

 Using Tomcat on CentOS Systems

 Using Tomcat on macOS Systems

 Connecting to SQL Server from Servlet

 Developing Web Applications with Servlet

 Archived Tutorials


 Full Version in PDF/EPUB