Advertisement



< Prev
Next >



JSP request Object





JSP built-in objects are implicitly created when your JSP webpage is invoked, hence these built-in objects are automatically available to use in your JSP code. Some of JSP built-in objects are - Today we are doing to understand how to use JSP built-in request object.




JSP request Object


JSP inbuilt request object is used to retrieve data entered by the user in a form on a web page. This data can be used for validation purpose in order to send the appropriate response to the user based on the input. The request object is of type javax.servlet.http.HttpServletRequest interface, which is itself a subclass of javax.servlet.ServletRequest interface.




Some useful methods available to request object.


The methods in the table below are part of javax.servlet.http.HttpServletRequest interface and its superclass javax.servlet.ServletRequest. Hence, these methods are available to the JSP implicit request object.

Methods Description
Object getAttribute(String name) This method returns the value of the attribute named name.
Enumeration getAttributeNames() This method returns the name of all attributes in an HTTP request.
String getParameter() This method returns the value of request parameter as String or null if parameter doesn't exist.
Enumeration getParameterNames() This method returns the names of all parameters in request.
String getContentType() This method returns the MIME type of the request or null for an unknown type.
String getProtocol() This method returns name of the protocol and its version used by the request.
String getRemoteAddr() This method returns IP address that the request came from.
String getServerName() This method returns the name of Server that received the request.
int getServerPort() This method returns Server port at which the request is received.
boolean isSecure() This method returns true if the request came from HTTPS protocol and false if it didn't.
Cookies getCookies() This method returns an array of Cookie objects that came along with this request.
String getMethod() This method returns the name of the method(GET, PUT, POST) using which the request was made.
String getRequestURI() This method returns the URI of the page that initiated the request.



Advertisement




Example of JSP request object


We have created a JSP web page which has receive the request and we will use JSP implicit request object to extract the information about the sent request.

Request1.jsp
<html>

<head>
<title>Using JSP built-in request object</title>
</head>


<body>

<h2>Information retrieved from the request object - </h2>

JSP request came from : <%= request.getRequestURI() %> <br/>
Protocol of request : <%= request.getProtocol()%> <br/>
IP address of request : <%= request.getRemoteAddr() %> <br/>
Server name : <%= request.getServerName()%> <br/>
Server Port : <%= request.getServerPort() %> <br/>
Is request secure : <%= request.isSecure() %> <br/>
Content-type of request : <%= request.getContentType() %> <br/>
JSP request method  : <%= request.getMethod() %> <br/>
</body>

</html>



executing this JSP page displays the information about the sent request.



The remote IP address of the request is shown as 0:0:0:0:0:0:0:1 because we are trying to access request which is sent from the same local machine.




Please share this article -




< Prev
Next >
< JSP useBean Action
JSP response object >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement