JSP9 a built-in object

Source: Internet
Author: User
Tags server port

The first object of the JSP is an out object to output information to the client

Out indicates the output of various data to the client//the output buffer can be managed by the page property to change the buffer out.println ("Out.print"); Out.newline ("Cao"); Out.println ("< Br/> "); Out.print (" Cao ");

The flush buffer can be used

Force Flush Buffer Data Out.flush ();

Empty the buffers, and the front output will be emptied out.

Empties the data in the buffer Out.clearbuffer (); Out.clear ();
Out.println ("Get Current buffer size:" + out.getbuffersize ()); Out.println ("Number of bytes remaining in the current buffer:" + out.getremaining ());


The difference is that clear and flush conflict and Clearbuffer will not conflict with flush

Request object is used to encapsulate the client's requests

Requested method name <%= Request.getmethod ()%> <br/> requested URL <%= request.getrequesturi ()%> get the requested protocol <%= Request.getprotocol ()%> gets the server's Ip<%=request.getservername ()%> The requested server Port <%=request.getserverport ()%> The IP address of the client <%= request.getremoteaddr ()%> the host name of the client <%= request.getremotehost ()%><!--get form data parameter parameters are consistent with the form name-- >


First, create a submitted form

<pre name= "code" class= "java" ><form action = "do_register.jsp" method = "POST" > user name <input type = "text" Nam E = "UserName"/></br> skill <input type = "checkbox" name = "skills" VALUE = "java" >java<input type = "Check Box "name =" skills "value =" OC ">oc<input type =" checkbox "name =" skills "value =" Swift ">Swift</br>< INPUT type = "submit" value = "commit"/><input type = "reset" value = "Reset"/></form>

After the parameter is returned in the do_register.jsp, see if the property is subsequently configured to be set

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Here is the process registration is successful, after successful jump to the welcome.jsp file

Use GetParameter to get

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
This is to differentiate between getparameter to handle client requests and setattribute to represent the values between webpages



Response method, which is used to return the client's request

<%//set the Header Information Settings page data does not cache Response.setheader ("Cache-control", "No-cache");//set to refresh every two seconds Response.setintheader (" Refresh ", 2); Out.println (" date is "+ New Java.util.Date (). toString ());%>

Set up a direct jump to a page

Implement the page Jump Response.sendredirect ("http://www.baidu.com");
The session object is used to set the conversation when the browser requests to the server, there is only one SessionID server that will make the same decision to give a response

<% @page import= "java.util.Date"%><%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >


Implement a login verification first create a form in login

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Subsequent verification of the login in the validation form do_login.jsp

Configure properties in session

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Then output different values in the Welcome interface based on the different values obtained by the session

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >

Then exit by exiting the login interface.

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" ><%// Exit code session.invalidate (); Response.setheader ("Refresh", "2; Url=welcome.jsp ");%>

The Config property is configured primarily in SEVERLT and can be configured in the Web. xml file in the Web-inf directory

The Application property is used to set global variables

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Can make a simple counter if the page is the first access to the output value, and then save to application, if it is the second time to start Access, then the value is taken from the application, followed by + + and save worth operation

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
The page property is equivalent to the this pointer in Java, which is used to point to this page, which is inherited from the object class

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
The exception class must be configured with the Error_page property

An error is specified in the throw_error.jsp and then thrown, specifying the error interface as handle_error.jsp

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%>   <% @page errorpage=" handle_error.jsp "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Then specify Iserrorpage = True in handle_error.jsp and then output some of the abnormal information to

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "    pageencoding=" UTF-8 "%>    <% @page iserrorpage=" true "%> <! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
Page_context can be said to be a synthesizer, he can be converted to out but the system is already with an out by default, so you can only name the other name

<%jspwriter myout = Pagecontext.getout (); Myout.println ("Hello World");
You can also set values in the session, and then perform values and outputs

Pagecontext.setattribute ("Dakim", "Cao", Pagecontext.session_scope); String value = Session.getattribute ("Dakim"). toString (); out.println (value);

A good blog can refer to

http://blog.csdn.net/yenange/article/details/5949518






JSP9 a built-in object

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.