Request Object Example
The request object is created for each request and once the response is submitted then it gets destroyed. The request object is used to pass the information from one page to the other page if the pages are getting invoked during the request lifecycle. The below example will print all the request attributes as well as it gets the information passed from outer page to inner page.
requestexample.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<body>
<p><font size="5">Request Information:</font></p>
<table border="1" cellpadding="0" cellspacing="1">
<tr>
<td width="33%"><b>Request Method:</b></td><td width="67%"><%=request.getMethod()%></td>
</tr>
<tr>
<td width="33%"><b>Request URI:</b></td><td width="67%"><%=request.getRequestURI()%></td>
</tr>
<tr>
<td width="33%"><b>Request Protocol:</b></td><td width="67%"><%=request.getProtocol()%></td>
</tr>
<tr>
<td width="33%"><b>Path Info:</b></td><td width="67%"><%=request.getPathInfo()%></td>
</tr>
<tr>
<td width="33%"><b>Path translated:</b></td><td width="67%"><%=request.getPathTranslated()%></td>
</tr>
<tr>
<td width="33%"><b>Query String:</b></td><td width="67%"><%=request.getQueryString()%></td>
</tr>
<tr>
<td width="33%"><b>Content length:</b></td><td width="67%"><%=request.getContentLength()%></td>
</tr>
<tr>
<td width="33%"><b>Content type:</b></td><td width="67%"><%=request.getContentType()%></td>
</tr>
<tr>
<td width="33%"><b>Server name:</b></td><td width="67%"><%=request.getServerName()%></td>
</tr>
<tr>
<td width="33%"><b>Server port:</b></td><td width="67%"><%=request.getServerPort()%></td>
</tr>
<tr>
<td width="33%"><b>Remote user:</b></td><td width="67%"><%=request.getRemoteUser()%></td>
</tr>
<tr>
<td width="33%"><b>Remote address:</b></td><td width="67%"><%=request.getRemoteAddr()%></td>
</tr>
<tr>
<td width="33%"><b>Remote host:</b></td><td width="67%"><%=request.getRemoteHost()%></td>
</tr>
<tr>
<td width="33%"><b>Authorization scheme:</b></td><td width="67%"><%=request.getAuthType()%></td>
</tr>
</table>
<%request.setAttribute("information","This is information passed from outer page");%>
<jsp:include page="requestinner.jsp"/>
</body>
</html>
|
requestinner.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
The Passed value from the Outer page is :-
<%=request.getAttribute("information")%>
</body>
</html>
|
Output:-
