Java Servlet API Description Document

xiaoxiao2021-03-06  76

This is a documentation about version 2.1 Java Servlet API, as a supplement to this document, you can download the javadoc formatted documentation in http://java.sun.com/products/serve/index.html. Who needs to read this document describe the latest version version 2.1 of the Java Servlet API. Therefore, this book applies to the developers of servlets and servlet engines. The composition of the Java Servlet API is composed of two packages: one is a software package corresponding to HTTP, and the other is a universal package that does not correspond to HTTP. These two packages exist while the Java Servlet API can adapt to future other requests-responding protocols. This document and documents that have just mentioned Javadoc formats describe these two packages, and the documentation in Javadoc format also describes how you should use all methods in these two packages. For specification you may interested in these Internet norms, these specifications will directly affect the development and implementation of the Servlet API. You can find all of these RFC specifications mentioned below from http://info.internet.isi.edu/7c/in-notes/rfc/.cache. RFC 1738 Unified Resource Locator (URL) RFC 1808 Related Unified Resource Locator RFC 1945 Hypertext Transport Protocol - HTTP / 1.0 RFC 2045 Multi-Purpose Internet Mail Extensions (Multi-Used Internet Save Extension Protocol (MIME)) Part: Internet Information Body format RFC 2046 Multi-Use Internet Mail Extension (Multi-Used Internet Snap Extension Protocol (MIME)) Part II: Media Type RFC 2047 Multi-Use Internet Snap Protocol (MIME) (Multi-Use Internet Mail Extension) Part III: Information Title Extended for non-ASCII text RFC 2048 Multi-purpose Internet Mail Extensions (Multi-purpose Internet Snap Protocol (MIME)) Part 4: Register Step RFC 2049 Multi - Use Internet Mail Extensions (Multi-Use Internet Save Extension Protocol (MIME)) fifth Part: Consistency Standards and Example RFC 2068 Hypertext Transfer Protocol - HTTP / 1.1 RFC 2069 An Extension HTTP: Summary Access Identification RFC 2109 HTTP Status Management Matter RFC 2145 HTTP Release Number Usage and Explanation RFC 2324 Super Text Coffee Pot Control Protocol (HTCPCP / 1.0) The World Wide Web Association (http://www.w3.org) manages specification and execution of these protocols. About Java Servlets Javatm Servlets is a Java applet that is not subject to platform constraints, which can be used to expand the functionality of a web server through a variety of ways. You can understand the Applets on the Server, which is compiled into a zona code so that it can be dynamically loaded and efficiently expanded to extend the processing power of the host. Different parts of Servlets and Applets are that it does not run on a web browser or other graphical user interface. The servlet is running in the web server through the servlet engine to perform a request and response, a typical example of the request, and a response is an HTTP protocol. A client program can be a web browser, or non-other programs that can connect to the Internet, which will access the web server and issue a request. This request is running the servlet engine on the web server and returns a response to servlet. The servlet forwards this response to the client via HTTP.

In terms of function, servlet is a bit similar to CGI, NSAPI, but different from them is that servlet has platform independent. The Java Servlet Annual Servlet has the following progress: because it uses different process processing mode, it is faster than CGI. It uses the standard APIs supported by many web servers. It inherits all the advantages of Java, including easy upgrade, and platform-independent. It can call the functional modules of a large number of APIs provided by Java. This document illustrates the method of the class and interface of the Java Servlet API. For more information, see the API description below. The lifecycle of the servlet has a Java Servlet with a lifecycle. This lifecycle defines how a servlet is loaded and initialized, how to receive requests and make a response to requests, how to clean it from the service. The lifecycle of the servlet is defined by the interface of javax.servlet.servlet. All Java servlets will execute the javax.servlet.servlet interface directly or indirectly so that it can run in a servlet engine. The servlet engine is a Web server that is customized by the Java Servlet API. The Servlet engine provides network services that can understand the MIME request and provide a container running servlet. The Javax.Servlet.Servlet interface defines the method of a specific time in the lifecycle of the servlet and the specific order. The parsing / R Servlet engine parsing and loads a servlet, which can occur when the engine starts, and needs a servlet to respond to requests, and at any time between this. The servlet engine uses the Java class load tool to load a servlet, and the servlet engine can load the servlet from a local file system, a remote file system, and the network. After servlet, the servlet engine loads servlet, the Servlet engine must initialize the servlet. In this process, you can read some fixed storage data, initialize the JDBC connection, and establish a connection to other resources. In the initialization process, the init () method of the Javax.serveT.Servlet interface provides the initialization information of the servlet. This way, servlet can configure it yourself. The init () method obtains a servletconfig. This object is executed in the servlet engine and allows servlets to be related parameters from it. This object allows the servlet to access the ServletContext object. After the servlet processing request / R servlet is initialized, it has been able to handle a request from the client, each request from the client being described as a servletRequest object, and the Servlet response is described as a servletResponse object. When the client issues a request, the Servlet engine passes a servletRequest object and a servletResponse object, which is passed as a parameter into the service () method. The servlet can also perform the servletRequest interface and servletResponse interface. The servletRequest interface allows servlets to use the requests issued by the client. The servlet can read the request information through the ServletInputStream object.

The servletResponse interface allows the servlet to establish a response header and status code. By performing this interface, servlet has the right to use the ServletOutputStream class to return data to the client. Multi-threaded and mapping / r In multi-threaded environments, the servlet must be able to handle many simultaneous requests. The exception is that this servlet executes a SingLethReadModel interface. If so, servlet can only process a request at the same time. The servlet responds to the client's request in accordance with the mapping of the Servlet engine. A mapping pair includes a servlet instance and a URL that returns data, for example: helloservlet with /hello/index.html. However, a mapping may be composed of a URL and a number of servlet instances, such as: a distributed servlet engine may run in more than one server, in which, there may be a servlet instance in each server to balance the process Load. As a servlet developer, you can't assume that a servlet has only one instance. Servlet's uninstall Servlet Engine does not have to ensure that a servlet is loaded at any time or at any time on service. The servlet engine can freely use or clear a servlet at any time. Therefore, we cannot rely on a class or instance to store important information. When the Servlet engine decides to uninstall a servlet (for example, this engine must allow the servlet to release the resources being used and store the relevant information. In order to complete the above work, the engine calls the servlet's Destroy () method. Before uninstalling a servlet, the Servlet engine must wait for all service () methods to complete or timeout (the servlet engine will define the timeout). When a servlet is uninstalled, the engine will not send any requests to the servlet. The engine must release the servlet and complete the use of the Servlet mapping technology / R as a servlet engine. You must have a lot of adaptability to how to map the client's request to servlet. This document does not specify how the mapping occurs. However, you must be able to freely use all of the following techniques: Map a servlet to a URL, for example, you can specify a special servlet it is only called from /FeedBack/index.html. Map all URLs starting with a specified directory name For example, you can map a servlet to / catalog, so requested from / catalog /, / catalog / garden and /catalog/HouseWares/index.html will be mapped to This servlet. But requests from / catalogtwo or /catalog.html are not mapped. Map a servlet to all URLs ending with a specific field, for example, you can map a request from all in in.thtml to a specific servlet. Map a servlet to a special URL / servlet / servlet_name. For example, if you have established a servlet called Listtributes, you can access this servlet by using / servlet / listattributes.

Calling servlets, for example, if the Servlet engine receives requests from /Servlet/com.foo.servlet.mailServlet, the servlet engine will load this com.foo.servlet.mailServlet class, create an instance, and processes this servlet. request. The servlet environment servletContext interface defines a servlet environment object, which defines a view of a servlet on the Servlet engine. By using this object, the servlet can log events to get resources and get classes from the Servlet engine (for example, the RequestDispatcher object). A servlet can only run in a servlet environment, but different servlets can have different views on the Servlet engine. If the Servlet engine supports virtual hosts, each virtual host has a servlet environment. A servlet environment cannot be shared between the virtual host. The Servlet engine allows a servlet environment to have its own range of activities. For example, a servlet environment is a Bank application, which will be mapped to the / Bank directory. In this case, a call to the GetContext method returns / bank's servlet environment. The HTTP session HTTP is an uncleary protocol. To create an effective web service application, you must be able to identify a unique request from the remote client from the remote. Over time, many session tracking technologies have been developed, but it is more troublesome. The Java Servlet API provides a simple interface that allows the servlet engine to track the user's session. Establishing the session because HTTP is a request-response protocol, a session is considered a new session before the client is joined. Joining means returning session tracking information into the server, pointing out that the session has been established. Before the client is joined, we cannot judge that the next client request is part of the current session. In the case, Session will be considered a new session. The client's session does not know before the client selection does not join the session, for example, if the client refuses to receive cookies from the server as a servlet developer, you must decide whether your web application handles the client does not join or not join SESSION. The server maintains a session object within the time specified by the web server or servlet. When the session terminates, the server releases the session object and all objects that bind on the session. Binding objects to session If you help you handle the data requirements of your application, you may need to bind your object to the session, you can bind any objects through a unique name to Session, then you need to use HttpSession Object. Any object that binds to the session can be handled as a servlet call to the same session. Some objects may need you know when it will be placed in the session or remove from the session. You can get this information by using the HttpSessionBindingListener interface. When your application stores data into the session, or clear data from the session, servlet will be bind or cancelly bound by httpsessionBindingListener. The method of this interface will notify the object that is bound or canceled.

Package: Javax.Servlet.http includes interface: httpservletRequest; httpsession; httpsessionBindingListener; httpsessionContext. The class contained: cookie; httpservlet; httpsessionBindingEvent; httputils. 1. HTTPSERVLETREQUEST Interface Definition / Public Interface HttpServletRequest Extends ServletRequest; request information to process a HTTP format for servlet. Method 1, GetAuthtype Public String getAuthType (); returns the authentication mode of this request. 2, getCookies public cookie [] getCookies (); returns an array that contains all current cookies in this request. If there is no cookie in this request, an empty array is returned. 3, getDateHeader public long getdateHeader (String name); Returns the value of the specified request header field, which is converted into a long integer that reflects the accurate to milliseconds since 1970-1-1 (GMT). If the head domain cannot be converted, an IllegaLargumentException is thrown. This method returns -1 if this request header is not exist. 4, GetHeader Public String GetHeader (String Name); Returns a value of a request header field. (Translator Note: Different from the previous method, this method returns a string) If this request header is not existed, this method returns -1. 5, getHeadernames public enumeration getHeadernames (); This method returns a list of String objects that reflect all header names requested. Some engines may not allow access to the header in this way. In this case, this method returns an empty list. 6, getIntheader public int getinthead (String name); Returns the value of the specified request header field, this value is converted into an integer. If the head domain cannot be converted, an IllegaLargumentException is thrown. This method returns -1 if this request header is not exist. 7, GetMethod Public String getMethod (); Returns the HTTP method (for example: get, post, put) 8, getPathInfo public string getpathinfo (); this method returns the request URL after the servlet path of this requested URL Additional path information. If this request URL includes a query string, this query string will not be included in the return value. This path must be decoded by URL before returning. If there is no path information after the servlet path of this requested URL. This method returns null value.

9, getPathtranslated public string getPathTranslated (); this method gets additional path information after the servlet path of this request, and converts it into a real path. The requested URL must be decoded by the URL before conversion. If there is no additional path information after the servlet path of this URL. This method returns null value. 10, getQueryString Public String getQueryString (); Returns the query string included in this request URL. A query string is taken out in a URL. If you do not query strings, this method returns null value. 11, getRemoteUser public string getRemoteUser returns the username of the request, which is used to make HTTP user arguments. If there is no username message in the request, this method returns a null value. 12, getRequestedSessionId Public String getRequestedSessionId (); returns this request corresponding session ID. If the Session ID provided by a reason client is invalid, this session ID will be different from the Session ID in the current session, and will create a new session. If this request is not associated with a session, this method returns a null value. 13, getRequesturi Public String getRequesturi (); part of the requested resource defined in the requested URL returns from the first row of the HTTP request. If there is a query string exists, this query string will not be included in the return value. For example, a request to access the URL path to the / catalog / books? Id = 1, this method will return / catalog / books. The return value of this method includes servlet path and path information. If a part of this URL path passes URL encoding, the return value of this method must be decoded before returning. 14, GetServletPath Public String GetServletPath (); This method returns the request URL to reflect the part of the call servlet. For example, a servlet is mapped to the / catalog / summer this URL path, and a request uses the path to / catalog / summer / casal. The so-called part of the calling servlet refers to / catalog / summer. If this servlet is called by a path match. This method will return an empty value. 15, getsession public httpsession getsession (); public httpsession getsession (Boolean Create); Returns the current valid session associated with this request. If you don't have a parameter when calling this method, then a session will be created without the SESSION with this request. If this method is called, a Boolean parameter is brought, and the session will only be established when this parameter is true. To ensure that session can be fully maintained. The servlet developer must call the method before the response is submitted. If the parameters belled are false, and there is no session associated with this request. This method returns null value.

16, isRequestedSessionIdvalid public boolean isRequessesSessionIdValid (); this method checks the session that is associated with this request is currently valid. If the session used in the current request is invalid, it will not return to the getSession method. 17, isRequestedSessionIDFromCookie Public Boolean isRequestedSessionIDFromCookie (); if this request is provided through a cookie of the client, the method returns true, otherwise returns a false. 18, isRequestedSessionIdFromurl Public Boolean isRequestedSessionIDFromurl (); if this request is provided through part of the client's URL, the method returns true, otherwise it returns false. Note that this method is different from IsRequestedSessionIDFromurl spelling in the URL. The following method will be canceled // R 19, isRequestedSessionIDFromurl Public Boolean isRequestedSessionIDFromurl (); this method is replaced by IsRequestedSessionIDFromurl. Second, HTTPSERVLETRESPONSE Interface Definition // R Public Interface HttpServletResponse Extends ServletResponse Description An HTTP response returned to the client. This interface allows the servlet programmers to utilize the header information specified by the HTTP protocol.

Member variable public static final int SC_CONTINUE = 100; public static final int SC_SWITCHING_PROTOCOLS = 101; public static final int SC_OK = 200; public static final int SC_CREATED = 201; public static final int SC_ACCEPTED = 202; public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203; public static final int SC_NO_CONTENT = 204; public static final int SC_RESET_CONTENT = 205; public static final int SC_PARTIAL_CONTENT = 206; public static final int SC_MULTIPLE_CHOICES = 300; public static final int SC_MOVED_PERMANENTLY = 301; public static final int SC_MOVED_TEMPORARILY = 302; public static final int SC_SEE_OTHER = 303; public static final int SC_NOT_MODIFIED = 304; public static final int SC_USE_PROXY = 305; public static final int SC_BAD_REQUEST = 400; public static final int SC_UNAUTHORIZED = 401; public static final int SC_PAYMENT_REQUIRED = 402; public static final int SC_FORBIDDEN = 4 03; public static final int SC_NOT_FOUND = 404; public static final int SC_METHOD_NOT_ALLOWED = 405; public static final int SC_NOT_ACCEPTABLE = 406; public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407; public static final int SC_REQUEST_TIMEOUT = 408; public static final int SC_CONFLICT = 409; public static final int SC_GONE = 410; public static final int SC_LENGTH_REQUIRED = 411; public static final int SC_PRECONDITION_FAILED = 412; public static final int SC_REQUEST_ENTITY_TOO_LARGE = 413; public static final int SC_REQUEST_URI_TOO_LONG = 414;

public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415; public static final int SC_INTERNAL_SERVER_ERROR = 500; public static final int SC_NOT_IMPLEMENTED = 501; public static final int SC_BAD_GATEWAY = 502; public static final int SC_SERVICE_UNAVAILABLE = 503; public static final int SC_GATEWAY_TIMEOUT = 504; public static Final INT SC_HTTP_VERSION_NOT_SUPPORTED = 505; The above HTTP product status code is defined by http / 1.1. Method 1, AddCookie Public Void AddCookie (Cookie cookie); adds a specified cookie in the response. This method can be called multiple times to define multiple cookies. In order to set the appropriate head domain, the method should be called before the response is submitted. 2, ContainSheader Public Boolean ContainSheader; Check if the specified response header is set. 3, EncoderedirectURL PUBLIC STRING ENCODIRECTURL (String URL); encoding the specified URL used by the SendRedirect method. If you do not need to be encoded, you will return this URL directly. This additional coding method is provided because the rules that decide whether to encode the URL in the case of Redirect. The URL given must be an absolute URL. Relative URLs cannot be received, an IllegaLargumentException will be thrown. All URLs that provide to the SendRedirect method should run through this method, so that session tracking can run normally in all browsers. 4, EncodeURL Public String EncodeURL (String URL); encodes the URL containing the session ID. If you do not need to be encoded, you will return this URL directly. The servlet engine must provide a URL encoding method, because in some cases, we will have to rewrite the URL, for example, in response to the corresponding request containing a valid session, but this session cannot be non-URL (such as cookie) means To maintain. All URLs provided to servlet should run through this method, so that session tracking can run normally in all browsers. 5, senderror public void senderror (int statuscode "; public void senderror (int statscode, string message" throws ioException; send a given status code to the client an error response. If a Message parameter is provided, this will be issued as part of the responsive body, otherwise, the server returns the standard information corresponding to the error code. After calling this method, the response is immediately submitted. After calling this method, servlet will no longer have more output.

6. Sendredirect public void sendredirect (string location) THROWS IOEXCEPTION; uses a given path to issue a temporary steering response (SC_MOVED_TEMPORARILY). A given path must be an absolute URL. The relative URL will not be received and an IllegaLargumentException will be thrown. This method must be called before the response is submitted. After calling this method, the response is immediately submitted. After calling this method, servlet will no longer have more output. 7, setdateHeader public void setdateheader (String name, long Date); set the response head with a given name and date value, the date value here should be reflected in the accurate to milliseconds since 1970-1-1 (GMT) Long integer. If the response head has been set, the new value will overwrite the current value. 8, SetHeader Public Void SetHeader (String Name, String Value); set the response head with a given name and domain. If the response head has been set, the new value will overwrite the current value. 9, SetInTheader Public Void SetInTheader; Set the response header with a given name and shaping value. If the response head has been set, the new value will overwrite the current value. 10, SetStatus Public Void SetStatus (int status); This method sets the status code of the response, and if the status code has been set, the new value will overwrite the current value. Several methods will be canceled / 11, EncoderedirectURL PUBLIC STRING ENCODIRECTURL (String URL); this method is replaced by EncoderedirectURL. 12, EncodeURL PUBLIC STRING ENCODEURL (String URL); this method is replaced by EncodeURL. 13, SetStatus Public Void SetStatus (int statuscode, string message); This method sets the status code of the response, if the status code has been set, the new value will overwrite the current value. If a message is provided, it will also be sent as part of the responsive body. Third, the httpsession interface definition / public interface httpsession This interface is used by the servlet engine to implement both the HTTP client and the HTTP session. This association may continue a given time in multiple external connections and requests. Session is used to maintain status and identify users under the stateless HTTP protocol. A session can be maintained by cookie or rewriting the URL. Method 1, getCreationTime public long getCreationTime (); return to establish a session, this time is represented as a millisecond since 1970-1-1 (GMT). 2, getId public string getId (); returns the identifier assigned to this session. An Identifier of an HTTP Session is a unique string that is established and maintained by the server.

3, getlastaccessedtime public long setLastaccessedTime (); Return to the client to issue the time related to this session, if this session is new, return -1. This time is expressed as a millisecond since 1970-1-1 (GMT). 4, getMaxinactiveInterval public int getMaxinactiveInterval (); returns a second number of seconds, indicating that the client is maintained by the servlet engine when the client does not issue a request. After this time, the servlet engine may be terminated by the servlet engine. If this session is not terminated, this method returns -1. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 5, getValue public object getValue (String name); Returns an object that binds to the session at a given name. If there is no such binding, return null values. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 6, getValuenames public string [] getValuenames (); Name of all data binding to the session with an array. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 7, invalidate public void invalidate (); this method will terminate this session. All bindings on this session will be cleared. And make an announcement through the valueunbound method of the HTTPSESSSIONBINDINGLISTENER interface. 8, isnew public boolean isnew (); return a Boolean value to determine that this session is new. If a session has been established by the server but has not received the corresponding client request, this session will be considered new. This means that this client has not joined a session or is not recognized by sessions. You can't return the appropriate session authentication information when he issued the next request. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 9, PUTVALUE PUBLIC VOID PUTVALUE (String Name, Object Value); Binds a given object to the session at a given name. The binding of the existing same name will be reset. At this time, the valuebound method of the HTTPSessionBindingListener interface is called. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 10, RemoveValue Public Void RemoveValue (String Name); Cancel the object of the given name in the binding of the session. This method does not do if the object of the binding of a given name is not found. The valueunbound method for the HttpSessionBindingListener interface is called. When the session is invalid, call this method to throw an ILLEGALSTATEEXCEPTION. 11, SetMaxInactiveInterval Public Int SetMaxInactiveInterval (int Interval); Sets a second number indicating that the client is maintained by the servlet engine when the client does not issue a request.

The following methods will be canceled / 12, GetSessionContext public httpsessionContext getsessionContext (); returns the environment variables whose session is maintained. This method is canceled like all other httpsessionContext methods. 4. HTTPSESSIONBINDINGLISTENER Interface Definition / Public Interface HttpSessionBindingListener This object is added to the HTTP session, and the execution of this interface will notify any object being bound to this http session or cancel the bind from this HTTP Session. Method 1, ValueBound Public Void ValueBound (httpsessionBindingEvent Event); This method is called when an object is bound to the session. When the HttpSession.putValue method is called, the servlet engine should call this method. 2, valueunbound public void valueunbound (httpsessionBindingEvent Event); This method is called when an object is unbinded from the session. When the HttpSession.RemoveValue method is called, the Servlet engine should call this method. 5. HTTPSESSIONCONTEXT interface definitions / This interface will be canceled / public interface httpsessionContext This object is a single entity associated with a set of HTTP session. This interface is canceled due to safety, and it appears in the current version only for compatibility. The method of this interface returns the corresponding value to the definition of the previous version. Method 1, GetSession public httpsession getsession (String sessionid); used to return to the session associated with this session ID. Now return null values. 2, GetIDS public enumeration getIDS (); the list used to return to this environment. Now return a list of empty. 6. Cookie class / defined / public class cookie implements Cloneable This class describes a cookie, and you can refer to RFC 2109 with reference to Netscape Communications Corporation. Constructor PUBLIC Cookie (String Name, String Value); define a cookie with a name-value. This Name must be accepted by HTTP / 1.1. Name starting with character $ is retained by RFC 2109. A given Name If it cannot be accepted by HTTP / 1.1, this method throws an ILLEGALARGUMENTEXCEPTION. Method 1, getcomment public string getcomment (); returns a description describing this cookie purpose, if this description is not defined, return null values. 2, getdomain public string getdomain (); Returns the area where this cookie can appear, if the area is not defined, return null values.

3, getMaxage public int getMaxage (); this method returns the longest survival period specified by this cookie. This method returns -1 if this maximum survival period is not defined. 4, getName public string getName (); this method returns a cookie name. 5, getPath public string getpath (); returns this cookie's prefix for all URL paths, if not defined, return null values. 6, getsecure public boolean getsecure (); if this cookie is only returned by secure channel transmission, it will return false. 7, getValue public string getValue (); this method returns the value of the cookie. 8, getversion public int getversion (); Returns the version of the cookie. Version 1 is explained by RFC 2109. Version 0 Explanation by Netscape Communications Corporation. New construction cookie defaults to use version 0. 9, setcomment public void setcomment; if a user submits this cookie to another user, you must describe the purpose of this cookie by this explanation. Version 0 does not support this property. 10, setdomain public void setdomain (String Pattern); This method sets the properties of the cookie's valid domain. This property specifies the area where cookie can appear. A valid domain begins with a point (.foo.com), which means that this cookie can be seen in the area of ​​the specified domain analysis system (probably www.foo.com but not a.foo.com). By default, cookies can only return to save its host. 11, setMaxage public void setMaxage (int expiry); This method sets the longest survival of this cookie. After this survival period, cookies will be deadly. Negative numbers indicate that this cookie does not take effect, 0 will delete this cookie from the client. 12, setPath Public Void SetPath (String Uri); This method sets the path properties of the cookie. The client can only return cookies to the path starting with this given path string. 13, SetSecure Public Void SetSecure (Boolean Flag); pointed out that this cookie can only be sent through a secure channel (eg HTTPS). This will only be set when the Cookie value is sent using a security protocol to send this cookie value using a security protocol. 14, SetValue Public Void SetValue (String NewValue); Sets the value of this cookie, using Base64 encoding for binary data. Version 0 cannot use spaces, {}, (), = ,,, "", /,?, @ ,: and;

15. SetVersion Public Void Setversion (INT V); Settings Cookie's version number 7, httpservlet class / definition / public class httpservlets EXTENDS GenericServlet Implements Serializable This is an abstract class that simplifies the process of HTTP Servlet writing. It is an expansion of the GenericServlet class, providing a framework for processing HTTP protocols. The service method in this class supports, for example, standard HTTP methods such as GET, POST. This support process is implemented by assigning them to an appropriate approach (such as DOGET, DOPOST). Method 1, Dodelete Protected VoidDelete (HTTPSERVLETREQUEST, HTTPSERVLETRESPONSE) THROWS servleTexception, IOException; Classical method called by this class to process an HTTP DELETE operation. This operation allows client requests to delete URLs from the server. This operation may have a negative impact, and it is responsible for this user. The default execution result of this method is to return an HTTP BAD_REQUEST error. You must overload this method when you want to deal with Delete requests. 2, Doget Protected Void Doget (httpservletRequest Request, HttpservletResponse response) throws servletexception, IOEXCEPTION; is called by this class's service method to process an HTTP GET operation. This operation allows clients to simply "get" resources from an HTTP server. The overloading of this method will automatically support the HEAD method. GET operations should be safe and there is no negative impact. This operation should also be safely repeated safely. The default execution result of this method is to return an HTTP BAD_REQUEST error. 3, DoHead Protected Void Dohead (httpservletRequest Request, HttpservletResponse response) throws servletexception, IOException; is called by this class's service method to process an HTTP HEAD operation. The default case is that this operation will be performed in accordance with an unconditional GET method, which does not return any data to the client, but only returns header information that contains the length of the content. Like the GET operation, this operation should be safe and there is no negative impact. This operation should also be safely repeated safely. The default execution result of this method is to automatically handle the HTTP HEAD operation, which does not need to be performed by one subclass. 4, DoOptions Protected Void Doptions (HTTPSERVLETREQUEST, HTTPSERVLETRESPONSE) THROWS servleTexception, IOException; called the service method called to process an HTTP Option operation. This operation automatically decides which HTTP method to support.

For example, a servlet writes a subclass of httpservlets and overloads the Doget method, and DoOption will return to the head below: Allow: Get, Head, Trace, Options You generally do not need to overload this method. 5, Dopost Protected Void Dopost (httpservletRequest Request, httpservletResponse response) throws servletexception, ioException; called this class's service method call to process an HTTP POST operation. This operation contains the data of the requester, and servlet should follow him. This action may have a negative impact. For example, update storage data or online shopping. The default execution result of this method is to return an HTTP BAD_REQUEST error. When you want to handle the POST operation, you must overload this method in the subclass of the HTTPSERVLET. 6, DOPUT protected void doput (httpservletRequest request, httpservletResponse response) throws servletexception, IOEXCEPTION; is called by this class's service method to process an HTTP PUT operation. This operation is similar to sending files via FTP. This action may have a negative impact. For example, update storage data or online shopping. The default execution result of this method is to return an HTTP BAD_REQUEST error. When you want to handle the PUT operation, you must overload this method in the subclass of the HTTPSERVLET. 7. Dotrace Protected Void Dotrace (HTTPSERVLETREQUEST REQUEST, HTTPSERVLETRESPONSE) THROWS ServleTexception, IOException; is called by this class's service method to process an HTTP TRACE operation. The default execution result of this operation is to generate a response, which contains information that reflects all headers sent in the Trace request. When you develop servlets, in most cases you need to overload this method. 8, getlastmodified protected long getlastmodified (httpservletRequest request); returns the last modification time of this request entity. To support GET operations, you must overload this method to accurately reflect the last modified time. This will help the browser and proxy servers to reduce loading servers and network resources, making more efficient work. The number of returned is the number of milliseconds since 1970-1-1-1 (GMT). The default execution result is returns a negative number, which marks the final modification time unknown, it cannot be used by a conditional GET operation.

9, service protected void service (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException; public void service (ServletRequest request, ServletResponse response) throws ServletException, IOException; this is a Servlet the HTTP-specific program, it allocates a request to this class Other ways to support this request. When you develop servlets, in most cases you don't have to overload this method. 8. httpsessionBindingEvent Class / Definition / Public Class HttpSessionBindingEvent Extends EventObject This event is incorporated to connect to HttpSessionBindingListener when you listen to the httpsession binding and cancel binding. This may be a result of session being terminated or identified. The event source is httpsession.putValue or httpsession.removevalue. Constructor PUBLIC HTTPSESSIONBINGEVENT (httpsession session, string name); constructs a new HttpSessionBindingEvent by causing Session of this event and a binding or unbound object name. Method 1, getName public string getName (); returns the name of the object that occurs and unbinds the bound. 2, getsession public httpsession getsession (); returns the name of the Session that occurs and cancels the bound. Nine, httputils class / definition / public class httputils collects the static effective ways for HTTP Servlet. Method 1, getRequestURL PUBLIC STATIC STRINGBUFFER getRequestURL (httpservletRequest Request); rebestructs clients on the server to establish the requested URL. This method reflects different protocols (eg HTTP and HTTPS) and ports, but does not include query strings. This method returns a StringBuffer instead of a string so that the URL can be effectively modified by the servlet developer. 2, ParsepostData Public Static HashTable ParsepostData (INT LEN, SERVLETINPUTSTREAM IN); resolves a stream of data containing MIME type Application / X-WWW-FORM-URLENCODED, and creates a Hash Table with a key value-data pair. The key value here is a string, and the data is a list of values ​​corresponding to the string. A key value can appear once or more in POST data. Each time this key value occurs once, its corresponding value is added to the list of values ​​corresponding to the string in the Hash Table. The data read from the POST data will pass through the URL decoding, will be converted to a space to be transmitted by hexadecimal (eg,% xx) will be converted into characters.

This method throws an ILLEGALARGUMENTEXCEPTION when POST data is invalid. 3, ParseQueryString Public Static HashTable ParsequeryString (String S); parsing a query string and creates a Hash Table with a key value-data pair. The data here is a list of values ​​corresponding to the string. A key value can appear once or more. Each time this key value occurs once, its corresponding value is added to the list of values ​​corresponding to the string in the Hash Table. The data read from the query string will pass through the URL decoding, and will be converted to the space transmitted by hexadecimal (eg,% xx) will be converted into characters. This method throws an ILLEGALARGUMENTEXCEPTION when the query string is invalid.

转载请注明原文地址:https://www.9cbs.com/read-120864.html

New Post(0)