BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Request Implicit Object in JSP with examples

Last Updated: July 27, 2022 by Chaitanya Singh | Filed Under: JSP tutorial

In this tutorial, you will learn request implicit object in JSP. It is used to get the data on a JSP page which has been entered by user on the previous JSP page.

Methods of request Implicit Object

  1. getParameter(String name) – This method is used to get the value of a request’s parameter. For example at login page user enters user-id and password and once the credentials are verified the login page gets redirected to user information page, then using request.getParameter we can get the value of user-id and password which user has input at the login page.
    String Uid= request.getParameter("user-id");
    String Pass= request.getParameter("password");
  2. getParameterNames() – It returns enumeration of all the parameter names associated to the request.
    Enumeration e= request.getParameterNames();
  3. getParameterValues(String name) – It returns the array of parameter values.
    String[] allpasswords = request.getParameterValues("password");
  4. getAttribute(String name) – Used to get the attribute value.  request.getAttribute(“admin”) would give you the value of attribute admin.
  5. getAttributeNames() – It is generally used to get the attribute names associated to the current session. It returns the enumeration of attribute names present in session.
    Enumerator e = request.getAttributeNames();
  6. setAttribute(String,Object) – It assigns an object’s value to the attribute. For example I have an attribute password and a String object str which has a value “admin” then calling request.setAttribute(“password”, str) would assign a value admin to the attribute password.
  7. removeAttribute(String) – By using this method a attribute can be removed and cannot be used further. For e.g. If you have a statement request.removeAttribute(“userid”) on a JSP page then the userid attribute would be completely removed and request.getAttribute(“userid”) would return NULL if used after the removeAttribute method.
  8. getCookies() – It returns an array of cookie objects received from the client. This method is mainly used when dealing with cookies in JSP.
  9. getHeader(String name) – This method is used to get the header information of the request.
  10. getHeaderNames() – Returns enumerator of all header names. Below code snippet would display all the header names associated with the request.
    Enumeration e = request.getHeaderNames();
    while (enumeration.hasMoreElements()) {
        String str = (String)e.nextElement();
        out.println(str);
    }
  11. getRequestURI() – This method (request.getRequestURI()) returns the URL of current JSP page.
  12. getMethod() – It returns HTTP request method. request.getMethod(). For example it will return GET for a Get request and POST for a Post Request.
  13. getQueryString() – Used for getting the query string associated to the JSP page URL. It is the string associated to the URL after question mark sign (?).

Request Implicit Object Example

In the following example we are receiving the input from user in index.html page and displaying the same information in userinfo.jsp page using request implicit object.

index.html

<html>
<head>
<title>Enter UserName and Password</title>
</head>
<body>
<form action="userinfo.jsp"> 
Enter User Name: <input type="text" name="uname" /> <br><br>
Enter Password: <input type="text" name="pass" /> <br><br>
<input type="submit" value="Submit Details"/> 
</form>
</body>
</html>

userinfo.jsp

<%@ page import = " java.util.* " %>
<html> 
<body> 
<% 
String username=request.getParameter("uname"); 
String password=request.getParameter("pass"); 
out.print("Name: "+username+" Password: "+password);
%> 
</body> 
</html>

Output:
Upon running the above JSP page, it shows you the following screen with two text fields of uname and pass. User enters the name in name in uname field and password in the pass field. Once the details are entered, user clicks the Submit Details button, which redirects the user to userinfo.jsp page.
Request Implicit Object in JSP with examples

This is the output of userinfo.jsp page. See the code of “userinfo.jsp” page above. We have used getParameter() method of request implicit object to fetch the values of uname and pass field. These values are displayed on the “userinfo.jsp” page as shown below.
Request Implicit Object in JSP with examples

❮ JSP Implicit ObjectsJSP response ❯

Top Related Articles:

  1. Java Server Pages (JSP) Life Cycle
  2. JSP Scriptlet Tag (Scripting elements)
  3. Out Implicit Object in JSP with examples
  4. Config Implicit Object in JSP with examples
  5. Include Directive in JSP

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Comments

  1. karan sisodiya says

    March 21, 2017 at 5:19 PM

    i want to insert time from html into database using jsp

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

JSP Tutorial

  • Basics of JSP
  • Life cycle of JSP
  • JSP in Eclipse IDE

Scripting Elements

  • Scriptlet Tag
  • Expression tag
  • Declaration tag

Implicit Objects

  • Implicit Objects
  • JSP Request
  • JSP Response
  • JSP Config
  • JSP Application
  • JSP Session
  • JSP Out
  • JSP pageContext
  • JSP Exception
  • Validate session

JSP directives

  • JSP Directives
  • Include Directive

JSP Exception

  • Exception handling

JSP Action

  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty

Expression language

  • Expression language

JSP Custom Tags

  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap