Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

JSP Request Object

By Exforsys | on May 7, 2007 |
JSP Tutorials

JSP Request Object

In this JSP tutorial, you will learn about JSP request object, JSP request object methods, getParameter(String name), getParameterNames(), getParameterValues(String name), getQueryString(), getRequestURI(), getServletPath(), setAttribute(String,Object), removeAttribute(String)

The request object in JSP is used to get the values that the client passes to the web server during an HTTP request. The request object is used to take the value from the client’s web browser and pass it to the server. This is performed using an HTTP request such as: headers, cookies or arguments. The class or the interface name of the object request is http.httpservletrequest. The object request is written: Javax.servlet.http.httpservletrequest.

Methods of request Object:

There are numerous methods available for request Object. Some of them are:

  • getCookies()
  • getHeader(String name)
  • getHeaderNames()
  • getAttribute(String name)
  • getAttributeNames()
  • getMethod()
  • getParameter(String name)
  • getParameterNames()
  • getParameterValues(String name)
  • getQueryString()
  • getRequestURI()
  • getServletPath()
  • setAttribute(String,Object)
  • removeAttribute(String)

Below is a list of the usage with syntax and examples with explanation of each.

getCookies():

The getCookies() method of request object returns all cookies sent with the request information by the client. The cookies are returned as an array of Cookie Objects. We will see in detail about JSP cookies in the coming sections.  General syntax of getHeader() of request object is request.getHeader("String"). 

getHeader()request object returned value is a string.

For instance String exfosys = request.getHeader("exforsys")

The above would retrieve the value of the HTTP header whose name is exforsys in JSP.

getHeader(String name):

The method getHeader(String name) of request object is used to return the value of the requested header. The returned value of header is a string.  General syntax of getHeader() of request object is request.getHeader("String")

In the above the returned value is a String.

For instance:  String exfosys = request.getHeader("exforsys")

The above retrieves the value of the HTTP header named exforsys in JSP.

getHeaderNames():

The method getHeaderNames() of request object returns all the header names in the request. This method is used to find available headers. The value returned is an enumerator of all header names. General syntax of getHeaderNames() of request object is as follows: request.getHeaderNames();

In the above the returned value is an enumerator.

For example:  Enumeration exforsys = request.getHeaderNames();

The above returns all header names under the enumerator exforsys.

getAttribute(String name):

The method getAttribute() of request object is used to return the value of the attribute. The getAttribute() method returns the objects associated with the attribute. When the attribute is not present, then a null value is returned. If the attribute is present then the return value is the object associated with the attribute.  General syntax of getAttribute() of request object is  request.getAttribute()

In the above the returned value is an object.

For example:  Object exforsys = request.getAttribute("test");

The above retrieves the object stored in the request test and returns the object in exforsys.

getAttributeNames():

The method getAttribute() of request object is used to return the object associated with the particular given attribute. If the user wants to get names of all the attributes associated with the current session, then the request object method getAttributeNames() can be used. The returned value is an enumerator of all attribute names.  General syntax of getAttributeNames() of request object is request.getAttributeNames()

For example:  Enumeration exforsys = request.getAttributeNames();

The above returns all attribute names of the current session under the enumerator: exforsys.

getMethod():

The getMethod() of request object is used to return the methods GET, POST, or PUT corresponding to the requested HTTP method used.  General syntax of getMethod() of request object is  request.getMethod()

For example:

if (request.getMethod().equals("POST"))
{
………
…….
}

In the above example, the method returned by the request.getMethod is compared with POST Method and if the returned method from request.getMethod() equals POST then the statement in if block executes.

getParameter(String name):

getParameter() method of request object is used to return the value of a requested parameter. The returned value of a parameter is a string. If the requested parameter does not exist, then a null value is returned. If the requested parameter exists, then the value of the requested parameter is returned as a string.  General syntax of getParameter() of request object is request.getParameter(String name)

The returned value by the above statement is a string.

For example: String exforsys = request.getParameter("test");

The above example returns the value of the parameter test passed to the getParameter() method of the request object in the string exforsys. If the given parameter test does not exist then a null value is assigned to the string exforsys.

getParameterNames():

The getParameterNames() method of request object is used to return the names of the parameters given in the current request. The names of parameters returned are enumeration of string objects.  General syntax of getParameterNames() of request object is  request.getParameterNames()

Value returned from the above statement getParameterNames() method is enumeration of string objects.

Enumeration exforsys = request.getParameterNames();

The above statement returns the names of the parameters in the current request as an enumeration of string object.

getParameterValues(String name):

The getParameter(String name) method of request object was used to return the value of a requested given parameter. The returned value of the parameter is a string. If there are a number of values of parameter to be returned, then the method getParameterValues(String name) of request object can be used by the programmer. The getParameterValues(String name) method of request object is used to return all the values of a given parameter’s request. The returned values of parameter is a array of string objects. If the requested parameter is found, then the values associated with it are returned as array of string object. If the requested given parameter is not found, then null value is returned by the method.  General syntax of getParameterValues of request object is request.getParameterValues(String name)

The returned value from the above method getParameterValues() is array of string objects.

For example:   String[] vegetables = request.getParameterValues("vegetable");

The above example returns a value of parameter vegetable passed to the method getParameterValues() of request object and the returned values are array of string of vegetables.

getQueryString():

The getQueryString() method of request object is used to return the query string from the request. From this method, the returned value is a string.  General syntax of getQueryString() of request object is request.getQueryString()

Value returned from the above method is a string.

For example:  String exforsys=request.getQueryString();
out.println("Result is"+exforsys);

The above example returns a string exforsys from the method getQueryString() of request object. The value is returned and the string is printed in second statement using out.println statement.

getRequestURI():

The getRequestURI() method of request object is used for returning the URL of the current JSP page. Value returned is a URL denoting path from the protocol name up to query string.  General syntax of getRequestURI() of request object is request.getRequestURI()

The above method returns a URL.

For example:  out.println("URI Requested is " + request.getRequestURI());

Output of the above statement would be: URI Requested is /Jsp/test.jsp

getServletPath():

The getServletPath() method of request object is used to return the part of request URL that calls the servlet.  General syntax of getServletPath() of request object is request.getServletPath()

The above method returns a URL that calls the servlet.

For example:  out.println("Path of Servlet is " + request.getServletPath());

The output of the above statement would be: Path of Servlet is/test.jsp

setAttribute(String,Object):

The setAttribute method of request object is used to set object to the named attribute. If the attribute does not exist, then it is created and assigned to the object.  General syntax of setAttribute of request object is request.setAttribute(String, object)

In the above statement the object is assigned with named string given in parameter.

For example:   request.setAttribute("username", "exforsys");

The above example assigns the value exforsys to username.

removeAttribute(String):

The removeAttribute method of request object is used to remove the object bound with specified name from the corresponding session. If there is no object bound with specified name then the method simply remains and performs no function. General syntax of removeAttribute of request object is request.removeAttribute(String);

« « Advancements in Service Oriented Architecture
Why Improving Your Vocabulary Can Enhance Your Life » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • JSP Architecture

    April 29, 2007 - 0 Comment
  • Working with JSP Sessions

    April 18, 2010 - 0 Comment
  • JSP Introduction

    April 27, 2007 - 0 Comment
  • JSP Out Object

    May 5, 2007 - 0 Comment
  • JSP Environment Setup

    April 27, 2007 - 0 Comment
  • JSP Application Object

    May 5, 2007 - 0 Comment
  • JSP Tags

    April 27, 2007 - 0 Comment
  • JSP Directives

    April 27, 2007 - 0 Comment
  • JSP Page Directive

    April 28, 2007 - 0 Comment
  • JSP Directive Tag and Scriptlet tag

    April 28, 2007 - 0 Comment
  • Working with JSP Sessions

    April 18, 2010 - 0 Comment
  • JSP Response Object

    May 8, 2007 - 0 Comment
  • JSP Out Object

    May 5, 2007 - 0 Comment
  • JSP Application Object

    May 5, 2007 - 0 Comment
  • JSP Implicit and Session Objects

    May 4, 2007 - 0 Comment
  • Sell CC Fresh Visa,MasterCard,American Express,Discover All Country

    May 3, 2007 - 0 Comment
  • JSP Architecture

    April 29, 2007 - 0 Comment
  • JSP Page Directive

    April 28, 2007 - 0 Comment
  • JSP Directive Tag and Scriptlet tag

    April 28, 2007 - 0 Comment
  • JSP Introduction

    April 27, 2007 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Working with JSP Sessions
  • JSP Response Object
  • JSP Out Object
  • JSP Application Object
  • JSP Implicit and Session Objects

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT