Another variable that is predefined and useful is "request ". It is a javax. servlet. http. HttpServletRequest.
The "request" on the server side handles the work between the browser and the server. When you click Connect or enter a URL, the browser sends a "request" to the server for the URL and displays the returned data. As part of this "request", various types of data are available, including the files that the browser wants to obtain from the server; and if this request (request) it is sent by pressing the SUBMIT button. The data also includes information that the user typed into the form area.
The "request" variable of JSP is used to obtain the information of the request sent from the browser. For example, you can know the name of the client host, or you can only obtain the IP address of this host. The code for the previous tutorial is modified as follows:
<HTML>
<BODY>
<%
// This scriptlet declares and initializes "date"
System. out. println ("Evaluating date now ");
Java. util. Date date = new java. util. Date ();
%>
Hello! The time is now
<%
Out. println (date );
Out. println ("<BR> Your machines address is ");
Out. println (request. getRemoteHost ());
%>
</BODY>
</HTML>
There is also a similar variable, "response ". This variable affects the response sent to the browser. To better understand the meaning of this sentence, let's take an example. You can call response. sendRedirect (anotherUrl) sends a response to the browser, and then the browser sends a different request to the "anotherUrl ". This seems a little different from some of the JSP mechanisms we have encountered. For example, it includes another webpage or forwards the browser to another webpage.
This tutorial is characterized by an exercise after each tutorial. This exercise is: compile a JSP to output the complete line "Hello! The time is now. ", of course, you need to write a scriptlet for this string, including The HTML Tag. Here, we also need to remind you that these exercises are very helpful for consolidating your knowledge and understanding, so I hope all students will exercise carefully.