1 Response
A Send error response
. Senterror ()///with one parameter and 2 parameters
b Setting the response header
. SetHeader (String name,string value)//There are several more, here only one
Response Redirection: 302 procedure?
// 302The first one// response.setstatus (302); // response.setheader ("Location", Request.getcontextpath () + "/index.jsp"); // 302 The Second response.sendredirect ("/pra/index.jsp");
The response is timed to refresh the specified page (equivalent to timed redirection):
// regularly updated response.setheader ("Refresh", "5;url=" +request.getcontextpath () + "/index.jsp");
Byte stream/character stream of C-response body
D Request's Domain attribute its with session and application is called the three domains, each domain has its own setattribute () getattribute () RemoveAttribute () method
E-Response encoding
Server to set setcharacterencording ("Utf-8") and setContentType ("Text/html;characster=utf-8") when sending
This allows the browser (client) to be acquired before it is properly encoded
2 Request
A Get Ip/request method/browser type (identify user)/refer anti-theft chain
// get the hostname and other things // System.out.println (request.getremoteaddr ()); // System.out.println (Request.getmethod ()); // System.out.println (request.getlocaladdr ()); // System.out.println (Request.getheader ("user-agent")); // System.out.println (Request.getheader ("Refer"));
b How to get URLs
C Request parameters can be obtained regardless of whether get or post
Get: Parameter after URL
http://localhost:8080/pra/Aservlet?one=123&two=3213//Parameters and URLs used? Connection, between parameters with & connection, parameter name and value = Connection
Post: The parameter is in the request body
D forward/include Request forwarding process?
Forward: Only the header information of the previous servlet is retained, not the body, the first request body cannot be too large
Includ: Retains the header of the previous servlet and retains its body
Forwark/include and redirect relationships?
Redirect: Servlet may be changed in different requests (request and response)
Forward/include: Requests and response objects do not change in the same request
F Request Encoding
? When submitting a form on a page, if your page is of type utf-8, then the parameter you pass is the Utf-8 type.
? Post request: setcharacterencording ("Utf-8") and setContentType ("Text/html;characster=utf-8")
? GET Request: We use the Java string to do it ourselves.
Javaweb Response and Request Basics