Interfaces (interface) and abstract classes: Classes can inherit only one, interfaces can implement multiple, interfaces belong to special abstract classes
The concepts of interfaces and abstract classes are different. An interface is an abstraction of an action, and an abstract class is an abstraction of the root.
The abstract class represents what this object is. The interface represents what this object can do. For example, men, women, these two classes (if it's a class ...) ), their abstract class is human. Description, they are all human.
People can eat, dogs can eat, you can define "eat" as an interface, and then let these classes to implement it.
Therefore, in high-level languages, a class can inherit only one class (abstract class) (just as people cannot be both biological and non-living), but can implement multiple interfaces (eating interfaces, walking interfaces).
The methods of abstract classes can be abstract and non-abstract, which can be public
Interface must be public, abstract, static, final
HttpServletRequest and HttpServletResponse
HttpServletRequest inheritance and ServletRequest, you can use the Servlet method (Doget, Dopost )
Main methods: Getauthtype (); ---Returns the name of the certificate configuration to protect the servlet
Getcontextpath ();---Returns the URI of the partial request indicating the corresponding relationship of the context
GetCookies ();---Returns an array that includes the request cookie object sent by all clients
Getdateheader (java.lang.String name);--Returns the specified request header value and depicts the Date object with a long integer
GetHeader (java.lang.String name);--Returns the specified request header file as a character type
Getheadernames ();--return this request container all header file names using enumeration method
Getheaders (java.lang.String name);--Returns the enumeration of all values of the specified file header with a character-type Object
Getintheader (java.lang.String name);--Returns the value of the specified request file with the integer type
GetMethod ();--Returns the name of the HTTP method that handles this request
GetPathInfo ();--When a client sends a URL request, it returns the additional information path associated with it
GetPathTranslated ();--Return some extended path information after the servlet name, but convert it to his real address before query string
GetQueryString ();--Returns a query string after it is contained in the request URL
Getremoteuser ();--Returns the user's registration using this request, or null if the user has passed validation or failed validation
Getrequestedsessionid ();--Returns the session Id of the specified user
Getrequesturi ();--return part of the URL of this request from the name of this protocol to the first line of the HTTP request query string
Getrequesturl ();--re-establishing the URL when requested by the client
Getservletpath ();--return part of this request URL call servlet
GetSession ();--Returns the session associated with the current request if the request does not have a session to create a
GetSession (Boolean Create),---Returns the httpsession associated with this request, and if no session is created he is true and returns to the new session
Getuserprincipal ();--Returns an object of type Java.security.Principal Aohan the currently authenticated user name
Isreqeustedsessionidfromcookie ();--check if the session ID of this request is from a cookie
Isrequestedsessionidfromurl ();--Check whether the request for this session Id is from a partially requested URL
Isrequestedsessionidvalid ();--Check if the session ID of the request is valid
IsUserInRole (java.lang.String role);--Returns a Boolean flag used to determine whether the authenticated user is covered by the established role
The following begins HttpServletResponse (the object can send three types of data to the client: A. Response Header B. Status code c. Data)
Common applications:
A. Use OutputStream to write Chinese to the client:
String data = "China";
OutputStream stream = Response.getoutputstream ();//Gets a stream that writes data to the response object, and when the Tomcat server responds, the data in the response is written to the browser
Stream.Write (Data.getbytes ("UTF-8"));
At this time in the HTML page will appear garbled, because: the server will "China" according to the UTF-8 Code table encoding, the corresponding code value is assumed to be 98, 99, the server will send the code value to the browser. The browser is decoded by default according to GB2312, and the corresponding character in the GB2312 code table is not "China"
The correct code is as follows:
Response.setheader ("Content-type", "text/html;charset=utf-8");//Send a response header to the browser, set the browser to decode by UTF-8
String data = "China";
OutputStream stream = Response.getoutputstream ();
Stream.Write (Data.getbytes ("UTF-8"));
B. Use writer to write Chinese to the client:
PrintWriter writer = Response.getwriter ();
Writer.write ("China");//garbled, because when we write "China" to the response object, the Tomcat server must encode it in order to transmit the data over the network to the browser, because no encoding is specified, the default is Iso8859-1 ,
When the browser receives the data, according to GBK decoding must appear garbled
The correct code is as follows:
Response.setcharacterencoding ("Utf_8");//Setup response is encoded as UTF-8
Response.setheader ("Content-type", "text/html;charset=utf-8");//Send a response header to the browser, set the browser decoding method for the UTF-8, actually set the sentence, Response is also set by default to encode the UTF-8, but the best two sentences in development are used together
Response.setcontenttype ("Text/html;charset=utf-8"); the same as the code in the same sentence
PrintWriter writer = Response.getwriter ();
Writer.write ("China");
C. Using response for file download:
String Path = This.getServletContext.getRealPath ("/China. jpg");
String fileName = path.substring (path.lastindexof ("\ \"));
Response.setheader ("Content-disposition", "Attachment;filename" +urlencode r.encode (filename, "UTF-8"));//Set the response header, Tell the browser that the response is a download response, and if the file name contains Chinese, you must use URL encoding ... Read and write to a file