Request Parameters in JSP
In this section, you will study about the various request parameters.
HttpServletRequest interface is responsible for providing request parameters. Request Parameters are the data sent from client to the server side program.
We can get information like:
1. URL with request.getURL()
method,
2. Protocol with request.getProtocol() method,
3. Servlet Path
with request.getServletPath() method,
4. Path Info with out.print(util.HTMLFilter.filter(request.getPathInfo()))
method,
5. Query String with out.print (util.HTMLFilter.filter (request.getQueryString()))
method,
6. Content Length with request.getContentLength() method,
7. Content
Type with out.print(util.HTMLFilter.filter(request.getContentType()))
method,
8. Server name with request.getServerName() method,
9. Server Port with
request.getServerPort() method,
10. Remote User with request.getRemoteUser()
method,
11. Remote address with request.getRemoteAddr() method,
12. Remote host
with request.getRemoteHost() method,
13. Authorization scheme with request.getAuthType()
method,
14. Locale with request.getLocale() method.
Client browser passes values to the server during HTTP request and request object retrieves those values.
Here is the code of requestParameter.jsp
<html> <body bgcolor="white"> <h1> Request Parameters </h2> <b>Request Method:</b> <% out.print(util.HTMLFilter.filter(request.getMethod())); %> <br> <b>URI: </b><%= request.getRequestURI() %> <br> <b>Protocol:</b> <%= request.getProtocol() %> <br> <b>Servlet path:</b> <%= request.getServletPath() %> <br> <b>Path info:</b><% out.print(util.HTMLFilter.filter(request.getPathInfo())); %> <br> <b>Query string:</b><% out.print(util.HTMLFilter.filter(request.getQueryString())); %> <br> <b>Content length:</b><%= request.getContentLength() %> <br> <b>Content type:</b><% out.print(util.HTMLFilter.filter(request.getContentType())); %> <br> <b>Server name:</b><%= request.getServerName() %> <br> <b>Server port:</b><%= request.getServerPort() %> <br> <b>Remote user: </b><%= request.getRemoteUser() %> <br> <b>Remote address:</b><%= request.getRemoteAddr() %> <br> <b>Remote host:</b><%= request.getRemoteHost() %> <br> <b>Authorization scheme:</b><%= request.getAuthType() %> <br> <b>Locale:</b><%= request.getLocale() %> <br> <b>Browser:</b><% out.print(util.HTMLFilter.filter(request.getHeader("User-Agent"))); %> </body> </html> |
Output will be displayed as: