Today is the use of learning content processing HTTP Servlet Servlet to the HTTP request response process 1, Web browser, by opening a TCP Socket to a Web server socket initiates a HTTP request. Socket input stream contains the HTTP request data. Socket output stream contains the HTTP response data. 2, for each HTTP request, Web container will parse the input stream Socket HTTP request data, to create a request object. At the same time to create a response object, used to generate the output stream Socket HTTP response data. 3, Web container calls the Servlet requested the service () method, and request and response objects passed as parameters to the method. In the HttpServletResponse object inside a method can call the various methods to create the response mwww.baidu-8.net.cnessage. 4, HttpServletResponse object to Servlet to provide a PrintWriter object that can generate a response message Servlet. Set the status code status code classification 1,100 to 199: that the information of the code, mark the client should take other action, the request is in progress. 2,200 ~ 299: said client request successful. 3,300 ~ 399: that the resource file for has been removed, indicating the new address. 4,400 ~ 499: that the error caused by the client. 5,500 ~ 599: that caused by a server-side error. · SetStatus () method: parameter is the status code. But this is an outdated method. · SendError () method: This method generates a 404 status code response. And the ability to customize error message content. · SendRedirect () method: This method generates a 302 status code response. Parameter is the new URL. Sets a response header setHeader () method: used to set a specific name and value of the response headers. · SetContentType () method: Set the client returns a MIME content type. Most of the Servlet should use this method. Set message body text flow using the response object to pass the getWriter () method to get a PrintWriter output stream. Used to return the text. * Use the response object to pass a binary stream of getOutputStream () method to get a ServletOutputStream output stream. Binary used to send non-text information. Such as pictures, audio and more. ServletOutputStream is based on the byte, and its higher efficiency than PrintWriter. Set redirection using sendRedirect () method implementation in the 302 redirect status code, the browser will automatically track the Location response header content. Automatic steering of the new link. Can be used in Servlet sendRedirect () method to achieve redirection. sendRedirect () method uses a string as a parameter that represents a new URL address.

December 29, 2010 at 1:19 am by admin
Category: Uncategorized
Tags: , ,