Jsp (preferred for SUN Enterprise Applications) has the following nine basic built-in components (which can correspond to the six internal components of ASP ):
Request client request, which contains parameters from the GET/POST request
Response returned from the response webpage to the client
The pageContext page is managed here.
Session-related session Period
Content being executed by application servlet
Out is used to send response output.
Configuration servlet framework
Page jsp (preferred for SUN Enterprise Applications) page itself
Exception for the error webpage, exceptions not captured
You can use them to access servlets that execute jsp (the preferred choice for SUN Enterprise Applications) code. To avoid talking about too many details about Servlet APIs, let's examine what you can do with them:
Without using the formula, you can directly access the internal out object to print something to response:
<% Out. println ("Hello"); %>
You do not need to directly transmit parameters to JavaBean. You can obtain the parameter values according to the request parts:
<% String name = request. getParameter ("name ");
Out. println (name); %>.
And so on.
The following describes session objects.
Session status maintenance is a must for Web application developers. There are multiple ways to solve this problem, such as using Cookies, hiding form input fields, or directly attaching status information to a URL. Java Servlet provides a continuously Valid Session object between multiple requests, which allows users to store and extract session status information. Jsp (the preferred choice for SUN Enterprise Applications) also supports this concept in Servlet.
Many descriptions about Implicit objects can be seen in Sun's jsp (SUN's first choice for enterprise-level applications) Guide (the implicit meaning is that these objects can be referenced directly without explicit declaration, no special code is required to create its instance ). For example, the request object is a subclass of HttpServletRequest. This object contains all information about the current browser request, including Cookies, HTML form variables, and so on. The session object is also such an implicit object. This object is automatically created when the first jsp (preferred for SUN Enterprise Applications) page is loaded and associated with the request object. Similar to session objects in ASP, session objects in jsp (the preferred choice for SUN Enterprise Applications) are very useful for applications that want to complete a transaction through multiple pages.
To illustrate the specific application of the session object, we use three pages to simulate a multi-page Web application. The first page (q1.html) only contains an HTML form that requires the user name to be entered. The Code is as follows:
<HTML>
<BODY>
<Form method = post action = "q2.jsp (preferred for SUN Enterprise Applications)">
Enter your name:
<Input type = text name = "thename">
<Input type = submit value = "SUBMIT">
</FORM>
</BODY>
</HTML>
The second page is a jsp (preferred for SUN Enterprise Applications) page (q2.jsp (preferred for SUN Enterprise Applications). It extracts the thename value from the q1.html form through the request object, store it as the name variable and save the name value to the session object. The session object is a set of name/value pairs. Here, the name in the name/value pair is "thename", and the value is the value of the name variable. Because the session object remains valid during the session, the variables saved here are also valid for subsequent pages. Another task of q2.jsp (the preferred choice for SUN Enterprise Applications) is to ask the second question. The following is its code:
<HTML>
<BODY>
<% @ Page language = "java" %>
<%! String name = ""; %>
<%
Name = request. getParameter ("thename ");
Session. putValue ("thename", name );
%>
Your name is: <% = name %>
<P>
<Form method = post action = "q3.jsp (preferred for SUN Enterprise Applications)">
What do you like?
<Input type = text name = "food">
<P>
<Input type = submit value = "SUBMIT">
</FORM>
</BODY>
</HTML>
The third page is also a jsp (preferred for SUN Enterprise Applications) page (q3.jsp (preferred for SUN Enterprise Applications). The main task is to display the Q & A results. It extracts the value of thename from the session object and displays it to prove that although the value is input on the first page, it can be retained through the session object. Another task of q3.jsp (preferred for SUN Enterprise Applications) is to extract user input from the second page and display it:
<HTML>