Request & Response (request corresponding) Summary

Requesting information of the client in the request object is encapsulated, it can be understood by the customer demand, and to respond. It is an instance of class HttpServletRequest.

Common methods:

Reques class

Request ( "name1"): made anterior form "name" property to the value of name1 (direct ignored is get or post request method)
Request.getParameter ( "key"): Gets the parameters submitted form
Request.getRequestURL () toString. : get the request of the URL of
Request.UrlReferrer: get the source of the request, namely: a page from which came
Request.UserHostAddress: get the visitor's IP address
Request.Cookies: get all the browser sent me the Cookie, Cookie returns an array, from Cookie value inside it reads
request.getSession () Gets Session object
Request.MapPath (virtulPath): to convert the virtual path into the physical paths to the disk. Such as: Request.MapPath ( "/ a / b.aspx ") to give D: \ Test \ Web \ A \ b.aspx
request.setAttribute () field stores data in the Request
Request.setCharacterEncoding () encoding parameter setting request , post requests valid only
request.getMethod () Get the type of request (GET, post)
Request.getParameter () Gets the value of the request parameter
request.getAttribute () acquire the data stored in the domain
acquired all the data domain Request.getAttributeNames () return a enumeration enum class
Request.getContextPath () returns the current relative path WEB project (get the context path - focus)
request.getRequestDispatcher () Gets transponder, parameter path / beginning, on behalf of WebRoot (WEB current project root directory)

Response class
Response.Buffer equivalent Response.BufferOutput: Internal Buffer BufferOutput is called, in response to control whether to use the cache, defaults to true
the Response.Flush (): transmitting data to a cache area of the browser, which the latter Code does not continue.
Response.Clear (): Empty the cache data in the red before the cached data is not.
Response.ContentEncoding: encoded output stream.
Response.ContentType: output stream content type, such as: html (text / html) or plain text (text / plain) or jpeg images (Image / the JPEG)
response.setContentType ( "text / HTML; charset = UTF-. 8") ; request mode is garbled when post
prohibition setting response :( browser cache header)
    response.setHeader ( "the cache-Control", "cache-NO");
  response.setHeader ( "Pragma", "NO-cache") ;
  . response.setDateHeader ( "the Expires", -1);
response.setHeader ( "refresh", ". 5"); original page refresh time (setting message header) every 5 seconds
response.sendRedict ( "/ day5 / response / demo2. html ");

 

Guess you like

Origin www.cnblogs.com/JesonCoder/p/11752945.html