beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

Request Implicit Object in JSP with examples

By Chaitanya Singh | Filed Under: JSP tutorial

Here we will discuss request implicit object in JSP. It is mainly 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 associted to the URL after question mark sign (?).

Request Implicit Object Example

In the below 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>

Snapshots of above example

Once you run the above JSP code. It would show you the below screen with two text fields of username and password.

LoginPage

This is the output of userinfo.jsp page. Here we have fetched the id and password which has been entered by the user in login page.

UserInfoPage

Let us know if you have any questions regarding the JSP request implicit object. We will be happy to assist you!!

Enjoyed this post? Try these related posts

  1. Application Implicit Object in JSP with examples
  2. JSP Expression Tag – JSP Tutorial
  3. Java Server Pages (JSP) Life Cycle
  4. JSP include action tag – JSP Tutorial
  5. Session Implicit Object in JSP with examples
  6. JSP Scriptlets

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
  • Declaration tag
  • Expression tag
  • Scriptlets
  • Directives
  • Include Directive
  • Param Directive
  • Exception handling
  • Action tags
  • Include action
  • Forward action
  • useBean, setProperty & getProperty
  • Implicit Objects
  • Session implicit object
  • Validate session
  • Request implicit object
  • Response implicit object
  • Out implicit object
  • Application implicit object
  • Config implicit object
  • pageContext implicit object
  • Exception implicit object
  • Expression language
  • Custom Tags
  • Custom tag example
  • JSP Interview Q

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2021 BeginnersBook . Privacy Policy . Sitemap