The previous chapter mainly tells the concept of JSP built-in object; this time, this time, some ways to build a built-in object.
1, the main method of request object:
☉ gettribute (String Name) Returns the Name property value.
☉ GetaTtributeNames () Returns all attribute names of the Request object.
☉ getCookies () Returns the Cookies object of the client.
☉ GetHeader (String Name) Gets the file header information defined by the HTTP protocol.
☉ GetHeaders (String Name) Returns all values of the Request Header of the specified name.
☉ getMethod () gets the client to transmit data to the server.
☉ getParameter (String Name) Get the parameter value of the client to the server.
☉ getParameterNames () gets the name of all parameters of the client to the server.
☉ getParameterValue (String Name) Get all values of the specified parameter.
☉ getProtocol () Gets the name of the protocol that the client is transferred to the server.
☉ getQueryString () get the query string.
☉ getRequesturi () Get the client address that issues a request string.
☉ getRemoteAddr () Get the IP address of the client.
☉ getRemotehost () Get the name of the client.
☉ GetServerName () Get the name of the server.
☉ GetServletPath () Get the file path of the script file requested by the client.
☉ GetServerPort () Get the port number of the server.
☉ setttribute (String name, java.lang.Object objt) Sets the value of the request parameter named Name, which is specified by the OBJT of the java.lang.object type.
Example: [Request.jsp]
JSP Request Method: <% = request.getMethod ()%>
Request uri: <% = request.getRequesturi ()%>
Request Protocol: <% = request.getProtocol ()%>
Servlet Path: <% = request.getServletPath ()%>
Remote User: <% = request.getRemoteuser ()%>
Remote address: <% = request.getRemoteAdddr ()%>
Remote host: <% = request.getRemoteHost ()%>
Path Info: <% = request.getPathInfo ()%>
Path Translated: <% = request.getPathTranslated ()%>
Query String: <% = request.getQueryString ()%>
Content Length: <% = Request.getContentLength ()%>
Content Type: <% = request.getContentType ()%>
Server name: <% = request.getServerName ()%>
Server port: <% = request.getServerPort ()%>
Authorization scheme: <% = request.getAutHTYPE ()%>
The Browser You are using is <% = Request.getHeader ("User-Agent")%>
body>
html>
2, the main method of response object:
☉ AddCookie (cookie cook) Add a cookie object to save the client's user information.
☉ Addheader (String Name, String Value) Add HTTP file header information.
☉ ContainSheader (String Name) Determines if the HTTP file header of the specified name already exists.
☉ Senderror (int) sends an error information to the client.
☉ SetHeader (String Name, String Value) Sets the value of the HTTP file header of the specified name.
Example: Timed refresh [refresh.jsp]
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "java.util.date"%>
hEAD>
This page is used to illustrate the response object b>
The current time is: b>
<% response.setHeader ("Refresh", "10");%>
<%
Out.println (New Date ());
%>
body>
html>
3, OUT object main method:
☉ Out.print / Println (Boolean | Char | Char [] | Double | FLOAT | INT | Long | Object | String |) Outputs various types of data.
☉ Out.newline () Outputs a wrap character.
☉ Out.flush () Outputs the data in the buffer.
☉ Out.close () Turn off the output stream.
☉ Out.clearbuffer () Clear the data in the buffer and output the data to the client.
☉ Out.clear () Clear the data in the buffer, but does not output the data to the client.
☉ Out.getBuffersize () Get the size of the buffer.
☉ Out.getRemaining () Get the size of the space that is not occupied in the buffer.
☉ Out.isautoflush () Returns the Boolean value.
4, the main method of session object:
☉ GetaTtribute (String Name) Get information that is associated with the specified name Name.
☉ GetAttributeNames () Returns every property object stored in the Session object.
☉ getCreationTime () Returns the time created by Session.
☉ GetId () returns the unique identifier to generate it for every session. ☉ getLastAccessedTime () Returns the time that the current session object is last sent by the customer.
☉ getMaxinactiveInterval () Returns the total time (seconds).
☉ RemoveAttribute (String Name) Deletes information about the associated name Name.
☉ SetAttribute (String Name, Java.lang.Object Value) Sets the property value value value specified Name and stores in the Session object.
5, PageContext object main method:
☉ gettribute scope () Retrieves a range of specific named objects.
☉ FindAttribute () is used to implement a search for a named property in order to follow the order requested, session, and application range.
☉ SetAttribute () is used to set the named object in the range or specific range of the default page.
☉ RemoveAttribute () is used to delete the default page range or the object already named.
6. The main method of Application object:
☉ GetAttribute (String Name) Returns the value of the properties of the name Application object specified by name.
☉ gettributenames () Returns the name of all the properties of all Application objects.
☉ GetInitParameter (String Name) Returns the initial value of an attribute of an Application object specified by name.
☉ GetServletInfo () Returns the current version of the servlet compiler.
☉ SetAttribute (String Name, Object Object) Sets the property value Object of the Application object specified by the name name.
Example: Online.jsp] <% @ Page ContentType = "TEXT / HTML; Charset = GB2312"%>
><%
Integer I = (Integer) Application.getaTRibute ("counter");
String name = (string) Application.getaTRibute ("OnlineName");
// StringBuffer Total = New StringBuffer (Name);
%>
<% out.println ((String) session.gettribute ("UserName"));%> Hello:
font>
Current online number: <% = i%>
font>
Online People Total: <% OUT.PRINTLN (Name);%>
font>
Function Cancel () {
<%
IF (session.getattribute ("UserName")! = "" && session.getattribute ("username")! = null) {// cancelname is the logan name
String CancelName;
CancelName = (string) session.getattribute ("UserName");
//out.println (Cancelname);
// j is the initial location of CancelName in the total roster
// k for the total length of CancelName
// t is the end position of CancelName in the total roster
INT J, K, T;
J = Name.indexof (CancelName);
K = cancelname.length ();
T = J K;
//out.println(J);
//out.println (T);
StringBuffer Total = New StringBuffer;
Total = Total.delete (J-4, T);
i = new integer (I.intValue () - 1);
Application.SetaTRibute ("Counter", i);
Name = (string) Total.Tostring ();
Application.setttribute ("OnlineName", Name);
//out.println ("window.alert (" Name ") ")")
Session.setttribute ("UserName", "");
}
%>
}
->
script>
body>