Built-in object one:
out
object
introduction: out built-in object is responsible for outputting content to the browser (print, write, println)
method: print print data to the client (convert various types of data into strings)
method: write to the client Print data (character, character array, string)
method: println prints data to the client (converts various types of data into strings) and wraps it.
Built-in object two:
request
object
introduction: the request built-in object is used to process client requests
Method: setCharacterEncoding() (sets the encoding format of the data stored in the request, excluding the rul encoding format).
Usage: According to the method of form submission (POST, GET)
POST: setCharacterEncoding("UTF-8");
GET: String name = request.getParameter("name");
name = new String(name.getBytes("ISO-8859 -1"),"UTF-8");
GET: modify tomcat\conf\server.xml
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
Method: getParameter("userName") (Get a single component (<input name= "userName" type="text">) parameter value)
method: getParameterValues("no1") (returns an array object)
<input type="checkbox" value="3000" name="no1"><a> Notebook: 3000</a>
<input type="checkbox" value="6000" name="no1"><a>Computer: 6000</a>
<input type="checkbox" value="1000" name=" no1"><a>Mobile phone: 1000</a>
<input type="checkbox" value="1400" name="no1"><a>Ipad: 1400</a>
Built-in object three:
response
object
Introduction: The response object is used to respond to client requests and output information to the client
Method: sendRedirect(String location) (page redirection)
The client will resend the request to the specified URL
before and after redirection, and the client sends two requests to the server respectively. , that is to say, the data in the request object of the first request does not exist in the request object of the second request.
Method: forward() method of the RequestDispatcher object (forwarding: on the server side, the request is sent to other resources on the server to complete the processing of a request together, and the data in the request can be shared during the interaction of multiple pages)
RequestDispatcher rd = request.getRequestDispatcher(String location);
rd.forward(request,response);
Built-in object 4:
Session
object
introduction: The session object is responsible for managing the client session, the
session object is created when the browser accesses the server for the first time, the
session object The common methods are
: setAsetAttribute(String key, Object value): save the object value in the form of key/value
Method: getAttttribute(String key): Get the object value by key
Method: setMaxInactiveInterval(): Set the inactive time unit of the session to seconds
Method: invalidate(): Set the invalidation of the session object
Extension: Set the valid duration of the session on the project web. xml and tomcat's web.xml
<session-config>
<session-timeout>30</session-timeout> <!-- unit is minute -->
</session-config>
built-in object five:
application
object
introduction: realize user Data sharing
method between: void setAttribute(String key,Object value) Save the object value in the form of key/value
Method: Object getAttribute(String key) Get the object value by key
Method: String getRealPath(String path) Return the relative path Real path case: Integer count = application.getAttribute("count"
after the user logs in successfully )
if(count==null){
application.setAttribute("count",1);
}else{
application.setAttribute("count",count+1);
}
Commonly used built-in objects and methods for jsp data interaction
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326221508&siteId=291194637
Ranking