JSP - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

JSP Client Request

JSP Client Request

shape Description

JSP Client Request - The request object is one of the implicit objects created by the JSP container. For each client request, the JSP container creates a new request object to represent request. Request object has a package of Java. servlet. http. HttpServletRequest. Following are the methods of request objects which are used in a servlet. getHeaderNames(): It returns enumerator of all headers. Following is an example to this method. [java]Enumeration e = request.getHeaderNames(); while (enumeration.hasMoreElements()) { String str = (String)e.nextElement(); out.println(str); }[/java] getParameter(): It returns the string value. If value is not available, it returns null. Following is an example to this method. [java]Enumeration e= request.getParameterNames();[/java] getAttributeNames(): It returns enumeration object. Following is an example to this method. [java]Enumerator e = request.getAttributeNames();[/java] Following are the important header information which comes from browser side.
Header Description
Accept This header specifies the MIME types that the browser or other clients can handle.
Connection This header indicates whether the client can handle persistent HTTP connections. Persistent connections permit the client or other browser to retrieve multiple files with a single request.
Cookie This header returns cookies to servers that previously sent them to the client.
OJB(Object Java Bean) Apache
Referer This header indicates the URL of the referring Web page.

shape Conceptual Figure

When client request the server for the data, server will check it in the database and gives response to the client that may be HTML, JSP response.

shape Example

request.html [html]<html> <body> <form action="requestparam.jsp"> Your Site Name is:<input type="text" name="site"/></br> <input type="submit" value="submit"/> </form> </body> </html>[/html] Here added another file in the form action method that is requestparam.jsp and created text field to enter the site name that is Your Site Name is. requestparam.jsp [java] <h2> <% String site = request.getParameter("site"); out.println("<b>Your Site Name is :</b>"+ site); %> </h2> [/java] getParameter is the method of request it retrieves the site name and out.println is used to print the message line. Output Output will be as follows, where enter the name of the site then click on submit button. After enter the site name, following message line will be displayed.

Summary

shape Key Points

  • JSP Client Request - getCookies() method is used to deal with JSP cookies.
  • JSP Client Request - getRequestURL() method is used to invoke current JSP URL.
  • JSP Client Request - getMethod() method is used to give back Http request method.