JSP (4-3)

Source: Internet
Author: User
Tags date now

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.