Java Servlet API Description Document

xiaoxiao2021-03-06  14

Java Servlet API Description Document (2.1A) (1)

Translator's preface:

Recently, when I finally organized the servlet information, I couldn't find a Chinese Java Servlet API on the Internet, and the Java Servlet API attached to the JSP book was not complete, and this document has 2.1 The A version has been finalized in November 1998. So I decided to translate a Chinese document (some of whom have been omitted), interested readers can be from http://java.sun.com/products/serve/2.1/servletspec-2.1 .zip download the original reading.

Java Servlet API Description Document (2.1A)

November 1998

introduction

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

This document describes the latest version version 2.1 of the Java Servlet API. Therefore, this book applies to the developers of servlets and servlet engines.

Composition of Java Servlet API

The Java Servlet API is composed of two packages: one is a 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.

Specification

You may also be interested in the following Internet specifications, which 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 Transfer Protocol - HTTP / 1.0

RFC 2045 Multipurpose Internet Mail Extension (Multi-Used Internet Save Extension Protocol (MIME)) Part 1: Internet Information Format

RFC 2046 Multipurpose Internet Mail Extension (Multi-Used Internet Mail Expansion Protocol (MIME)) Part 2: Media Types

RFC 2047 Multi-Used Internet Mail Extension Protocol (MIME) Part III: Information Title Extensions For non-ASCII text

RFC 2048 Multipurpose Internet Mail Extension (Multi-Used Internet Mail Expansion Protocol (MIME) Part 4: Registration steps

RFC 2049 Multipurpose Internet Mail Extension (Multi-Used Internet Mail Expansion Protocol (MIME)) Part 5: Consistency Standards and Examples

RFC 2068 Hypertext Transmission Protocol - HTTP / 1.1

RFC 2069 A extended HTTP: Summary Access Identification

RFC 2109 HTTP Status Management Mechanism

Use and explanation of RFC 2145 HTTP version number

RFC 2324 Super Text Coffee Pot Control Protocol (HTCPCP / 1.0)

The World Wide Web Association (http://www.w3.org) manages the specifications and execution of these protocols.

Java servlets

JavaTM Servlets is a Java applet that is not subject to platform, which can be used to expand a web server with 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.

Java Servlet Introduction

Servlet has the following advances with other ordinary Server extension:

Because it uses different process processing modes, 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.

SERVLET lifecycle

A Java Servlet has a lifecycle. This lifecycle defines how a servlet is loaded and initialized, how to receive requests and make a response to requests, how to be removed 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.

Servlet analysis and loading / R

The servlet engine is analyzed and loaded into a servlet, which can occur when the engine is started, requiring a servlet to respond to requests, and at any time there.

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.

SERVLET initialization

After 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.

Servlet Process Request / R

After servlet is initialized, it can 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 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

The Servlet engine does not have to ensure that a servlet is loaded at any time or at any time on the 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 servlet and complete the collection of useless storage units.

Servlet Mapping Technology / R

As a developer of 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 only from /FEEDBACK/index.html.

Map a servlet to all URLs starting with a designated 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. Call servlet by class name

For example, if the Servlet engine receives a request from the /Servlet/com.foo.servlet.mailServlet, the Servlet engine will load this com.foo.servlet.mailServlet class, create an instance, and processes the request through this servlet.

Servlet environment

The 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.

HTTP session

HTTP is an unstormal agreement. 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.

Establish a 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 this.

Client selection does not add session, for example, if the client refuses to receive cookie from the server

As a servlet developer, you must decide whether your web application handles the client does not join or cannot join the 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 objects. 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.

Java Servlet API Description Document (2.1A) (2)

Description of the API object / r This part contains a detailed description of all classes and interfaces for the Java Servlet API. This note is similar to the Javadoc API, but this document provides more information.

The API contains two packages, twelve interfaces and nine classes.

Software package: javax.servlet

The interface included: RequestDispatcher; servlet; servletconfig; servletContext; servletRequest; servletReadModel.

The class: genericServlet; servletinputstream; servletoutputstream; servletException; unavailableException.

First, the RequestDispatcher interface:

definition:

Public interface requestdispatcher;

Define an object, receive a request from the client, and send it to the server's available resources (such as servlet, CGI, HTML files, JSP files). The Servlet engine creates a Request Dispatcher object that is used to encapsulate server resources defined by a particular URL.

This interface is dedicated to encapsulated servlet, but a servlet engine can create a Request Dispatcher object to encapsulate any type of resource.

The Request Dispatcher object is built by the servlet engine, not built by servlet developers.

method

1, Forward

Public Void Forward (ServletRequest Request, ServletResponse Response)

Throws servletexception, ioException;

It is used to transfer requests from this servlet to other server resources. This method can be used when a servlet is initially processed and requires other objects to respond to this.

When the Request object is passed to the target object, the requested URL path and other path parameters are adjusted to reflect the target URL path to the target object.

If a servletoutputstream object or PrintWriter object has been returned by the response, this method will not be able to use, otherwise this method will throw an IllegalStateException.

2, Include

Public Void Include (ServletRequest Request, ServletResponse Response)

Throws ServleTexception, IOException

Used to include the content of the response sent to other server resources. In essence, this method reflects the content of the server.

Request the object to pass to the target object, reflect the request URL path and path information of the call request. This response object can only call this ServletOutputStream object and PrintWriter object.

A servlet calling include the header field if this servlet calls the method (such as cookie) that must be set, this method will not guarantee normal use. As a servlet developer, you must properly solve those methods that may directly store the header field. For example, even if you use a session tracking, in order to ensure the normal work of the session, you must start your session began outside a servlet that calls include Include.

Second, the servlet interface.

Definition / R

Public interface servlet

This interface defines a servlet: a Java class that inherits this feature on the web server. method

1, INIT

Public void init (servletconfig config) THROWS servletexception;

After the servlet is instantiated in the servlet, the Servlet is exactly called the init method before the service is placed. Before calling the service method, the init method must be successfully exited.

If the init method throws a servletException, you can't place this servlet, if the init method is not completed within the timeout range, we can assume that this servlet does not have functions, and cannot be placed in the service.

2, Service

Public void service (servletRequest Request, ServletResponse Response)

Throws servletexception, ioException;

The Servlet engine calls this method to allow the servlet response request. This method cannot be called until the servlet is not successfully initialized. Before servlet is initialized, the servlet engine can block unresolved requests.

After a servlet object is uninstalled until a new servlet is initialized, the servlet engine cannot call this method.

3, DESTROY

Public void destroy ();

When a servlet is removed from the service, the servlet engine calls this method. The DESTROY method cannot be called when all threads are not exited or not all threads that are not allowed by the engine.

4, GetServletConfig

Public servletconfig getServletConfig ();

Returns a servletconfig object, as a servlet developer, you should store the servletconfig object via the init method so that this method can return this object. For your convenience, GenericServlet has done this when performing this interface.

5, GetServletInfo

Public String getServletInfo ();

Allow servlets to provide information about itself to the host's servlet. The returned string should be a plain text format without any flag (such as HTML, XML, etc.).

Third, servletconfig interface

Definition / R

Public Interface Servletconfig

This interface defines an object. With this object, the servlet engine configures a servlet and allows the servlet to get a description of the servletContext interface about it. Each servletconfig object corresponds to a unique servlet.

method

1, GetInitParameter

Public String GetInitParameter (String Name);

This method returns a String that contains the initialization parameters specified by the servlet. If this parameter does not exist, return null values.

2, GetinitParameterNames

Public Enumeration GetInitParameterNames ();

This method returns a list String object that includes all initialization parameter names of the servlet. If the servlet does not initialize the parameters, getInitParameterNames returns an empty list.

3, GetServletContext

Public servletContext GetServletContext ();

Returns the servletContext object of this servlet.

Fourth, servletContext interface

Definition / R

Public interface servletContext defines a servlet environment object, through which the servlet engine provides environmental information to servlet.

An environment object of a servlet must be at least one or one with the host it resides. In a servlet engine that handles multiple virtual hosts (for example, host header fields of HTTP1.1), each virtual host must be considered a separate environment. In addition, the servlet engine can also create an environment object corresponding to a set of servlets.

method

1, GetAttribute

Public Object GetAttribute (String Name);

Returns the attribute object specified in the Servlet environment object. Returns null values ​​if the property object does not exist. This method allows access to additional information that has not been provided in other methods of this servlet engine.

2, GetaTtributeNames

Public Enumeration GetAttributeNames ();

Returns a list of attribute names available in a servlet environment object.

3, getContext

Public servletContext getContext (String Uripath);

Returns a servlet environment object, which includes servlets and resources of a specific URI path. If the path does not exist, an null value is returned. The URI path format is /DIR/DIR/FileName.ext.

For security, if you access a restricted servlet's environment object through this method, an null value is returned.

4, getmajorversion

Public int getmajorversion ();

Returns the main version of the servlet API supported by the servlet engine. For example, for version 2.1, this method returns an integer 2.

5, getminorversion

Public int getminorversion ();

Returns the secondary version of the servlet API supported by the servlet engine. For example, for version 2.1, this method returns an integer 2.

6, getMimeType

Public String getMimetype (String file);

Returns the MIME type of the specified file. If this MIME type is unknown, an null value is returned. The MIME type is determined by the configuration of the servlet engine.

7, GetRealPath

Public String GetRealPath (String Path);

A format of a specified virtual path in accordance with the URL path format is: /DIR/DIR/FileName.ext. With this method, you can return String with a true path corresponding to the virtual path in accordance with the format. The format of this real path should be suitable for running this Servlet engine (including its corresponding path parser).

No matter what reason, if this process cannot be executed from the virtual path to the actual path, the method will return an null value.

8, getResource

Public url getResource (String uripath);

Returns a URL object that reflects the resources known to the servlet environment objects of a given URL address (format: /DIR/DIR/FileName.ext). Whether UrlstreamHandlers is not necessary for access to a given environment, the servlet engine must be executed. If a given path is not known, the method returns an null value.

This method is not exactly the same as the GetResource method of java.lang.class. The GetResource method of java.lang.class is looking for resources by loading class. This method allows the server to generate environment variables to any servlet for any resource, without having to rely on loading classes, specific areas, and more. 9, GetResourceAsStream

Public InputStream GetResourceSstream (String Uripath);

Returns an InputStream object that references the contents of the servlet environment object of the specified URL. If the servlet environment variable is not found, the null value will be returned, and the URL path should have this format: /DIR/DIR/FileName.ext.

This method is a convenient way to get URL objects through the getResource method. Note that when you use this method, Meta-Information (eg, content length, content type) will be lost.

10, GetRequestDispatcher

Public RequestDispatcher getRequestDispatcher (String Uripath);

If this specified path can find an active resource (such as a servlet, jsp page, CGI, etc.), return a specific URL RequestDispatcher object, otherwise, return an null value, the servlet engine is responsible for encapsulating the target with a Request Dispatcher object path. This Request Dispatcher object can be used to fully request.

11, GetServerInfo

Public String getServerInfo ();

Returns a String object that includes at least the name and version number of the Servlet engine.

12, log

Public void log (String MSG);

Public void log (String Msg, Throwable T);

Public void log (Exception Exception, String MSG); // This use will be canceled / r

Write the specified information to a log file of a servlet environment object. The log file written is specified by the servlet engine, but it is usually an event log. When this method is called by an exception, a stack tracking is included.

13, SetAttribute

Public Void SetaTribute (String Name, Object O);

Give a name that you specify in the SERVLET environment object.

14, RemoveAttribute

Public void Removettribute (String Name);

Remove an attribute from the specified servlet environment object.

Note: The following methods will be canceled / r

15, GetServlet

Public servlet getServlet (String name) Throws servletexception;

Originally used to return a servlet that specifies the name, if you have not found a null value. If this servlet can return, this means it has been initialized and can have been accepted. This is a dangerous approach. When calling this method, you may not know the status of the servlet, which may result in a problem with the server status. This method that allows a servlet to access other servlets is also the same.

Now this method returns an null value, in order to keep and previously compatible compatibility, this method is now not canceled. In the later API version, the method will be canceled.

16, GetServletNames

Public Enumeration GetServletNames ();

Originally used to return a list of String objects, which represents all known servlet object names in this servlet environment. This list always contains this servlet itself. This is also a dangerous approach based on the same reason as the previous method.

Now this method returns an empty list. In order to maintain and previously versions, this method is now not canceled. In the later API version, the method will be canceled.

17, GetServlets

Public Enumeration GetServlets ();

Originally used to return a list of all known servlet objects in this Servelet environment. This list always contains this servlet itself.

This is also a dangerous approach based on the same reasons for the GetServlet method.

Now this method returns an empty list. In order to maintain and previously versions, this method is now not canceled. In the later API version, the method will be canceled.

V. ServletRequest interface

Definition / R

Public Interface ServletRequest

Define objects generated by a servlet engine. Through this object, the servlet can obtain the data requested by the client. This object provides all the data including the parameters by reading the data of the request body, and all the data of the input stream.

method

1, GetAttribute

Public Object GetAttribute (String Name);

Returns the value of the specified attribute in the request, if this property does not exist, return an null value. This method allows access to some request information that does not provide other methods in this interface and other servlets placed within this request object.

2, GetaTtributeNames

Public Enumeration GetAttributeNames ();

Returns a list of all attribute names contained in this request.

3, getcharacterencoding

Public string getcharacterencoding ();

Returns the character encoding type of the input content in the request, and return null values ​​if the character encoding type is not defined.

4, getContentLength

Public int getContentLENGTH ();

Request the length of the content, returns -1 if the length is unknown.

5, getContentType

Public String getContentType ();

Returns the MIME type of the request data, if the type is unknown to return null values.

6, GetInputStream

Public servletinputstream getInputStream () throws oException;

Returns an input stream to read binary data from the request body. If you have obtained the result to read through the getReader method, this method will throw an ILLEGALSTATEEXCEPTION.

7, getParameter

Public String getParameter (String name);

Returns the value of the specified parameter with a String, if this parameter does not have a return null value. For example, in an HTTP Servlet, this method returns a value of the parameter generated by the specified query representation or a parameter value in a submitted form. If a parameter name corresponds to a few parameter values, this method can only return the first value in the array returned by the getParameterVALUES method. Therefore, if this parameter is (or possibly) multiple values, you can only use the getParameterVALUES method.

8, getParameternames

Public Enumeration getParameterNames ();

Returns a list of String objects of all parameter names, if no parameters are input, the method returns an null value.

9, getParameterValues

Public string [] getParameterValues; Returns the value of the specified parameter through an array of String objects, if this parameter does not exist, the method returns an null value.

10, GetProtocol

Public string getProtocol ();

Returns the protocol used to request, the form is the protocol / home version number. Supreme version number. For example, for an HTTP 1.0 request, the method returns http / 1.0.

11, GetReader

Public BufferedReader getReader () throws oException;

This method returns a buffered Reader to read the entity of the requested body, and its encoding method is in accordance with the encoding method of requesting data. If the input stream of this request has been called by GetInputStream, this method will throw an IllegalStateException.

12, GetRemoteAddr

Public String getRemoteAddddr ();

Returns the IP address of the sending requestor.

13, GetRemotehost

Public String getRemotehost ();

Returns the host name of the sending requestor. This method will return to the IP address if the engine can't or if the engine is not resolved (in order to improve performance).

Getscheme

Public String getscheme ();

Returns the mode of the URL used to request. For example, for an HTTP request, this mode is http.

15, GetServerName

Public string getServerName ();

Returns the host name of the receiving server.

16, GetServerport

Public int GetServerPort ();

Returns the port number of the received request.

17, SetaTRibute

Public void setttribute (String name, Object Object);

This method adds an attribute to the request, which can be used by other objects that can access this request object (eg, a nested servlet).

Note: The following methods will be canceled / r

GetRealPath

Public String GetRealPath (String Path);

Returns the true path corresponding to the virtual path, if this process cannot be performed because of some reason, the method will return an null value.

This method is repeated with the getRealPath method in the servletContext interface. In version 2.1, the ServletContext interface will clarify the mapping of all paths that a servlet can use. The result of this method will be exactly the same as the result of the getRealPath method in servletContext.

Sixth, servletResponse interface

Definition / R

Public Interface ServletResponse

Define objects generated by a servlet engine, through this object, servlet respond to the client's request. This response should be a MIME entity, which may be an HTML page, image data, or other MIME format.

method

1, getcharacterencoding

Public string getcharacterencoding ();

Returns the character encoding of the MIME entity. This character encoding can be a specified type or a type that is most matching with the client encoded by the client reflected by the request header field. In the HTTP protocol, this information is transmitted to the servlet engine via accept-charset.

For more information on character encoding and MIME, see RFC 2047.

2, GetOutputstream

Public servletOutputStream getOutputStream () THROWS IOException; returns an output stream of record binary response data.

If this response object has called GetWrit, IllegalStateException will be thrown.

3, GetWriter

Public PrintWriter GetWriter Throws oException;

This method returns a PrintWriter object to record the formatted response entity. If you want to reflect the character encoding used, you must modify the MIME type of the response. The Content type of the response must be set before calling this method.

If this encoding type is not provided, a unsupportedEncodINGException will throw a getOutputStream if this response object has called GetOutputStream.

4, SetContentLength

Public void setContentLength; INT LENGTH

Set the length of the content of the response, this method covers the previously set of content length.

In order to ensure the successful setting of the content length, this method must be called before the response is submitted to the output stream.

5, setContentType

Public void setContentType (String Type);

This method is used to set the Content type of the response. This type may be implicitly modified in some cases, and additional situations mention here may be set to MIME characters when the server finds necessary.

This method must be called before the response is submitted to the output stream to ensure successfully set the response to the output stream.

Seven, SingleThreadModel interface

Definition / R

Public interface SingLethreadModel;

This is a void, which specifies how the system handles calls to the same servlet. If a servlet is specified by this interface, then two threads will not be executed simultaneously in the service method in this servlet.

The servlet can achieve this guarantee by maintaining a separate servlet instance pool or by only one thread in the Servlet's service.

Eight, GenericServlet class / R

Public Abstract Class GenericServlet Implements Servlet,

ServletConfig, Serializable;

The presence of this class makes it easier to write servlets. It provides a simple solution that performs a method for the Servlet lifecycle and describes the servletconfig object and ServletContext objects when initialization.

method

1, DESTROY

Public void destroy ();

Here the Destroy method does not do anything else.

2, GetInitParameter

Public String GetInitParameter (String Name);

This is a simple way, which will call the same name of the servletconfig object.

3, GetInitParameterNames

Public Enumeration GetInitParameterNames ();

This is a simple way, which will call the same name of the servletconfig object.

4, GetServletConfig

Public servletconfig getServletConfig ();

Returns a description of the servletconfig object generated by this type of init method.

5, GetServletContext

Public servletContext GetServletContext ();

This is a simple way, which will call the same name of the servletconfig object. 6, GetServletInfo

Public String getServletInfo ();

Returns a String that reflects the servlet version.

7, INIT

Public void init () throws servletexception;

Public void init (servletconfig config) THROWS servletexception;

The init (servletconfig config) method is a simple way to initialize the life cycle of this servlet.

The init () method is used to expand your genericServlet class. When you use this method, you don't need to store the config object, nor does it need to call Super.init (config).

The init (servletconfig config) method stores the config object and then calls init (). If you overload this method, you must call Super.init (config) so that other methods of the GenericServlet class work.

8, log

Public void log (String MSG);

Public void log (String Msg, Throwable Cause);

Write the servlet class name and a given information through the servlet content object.

9, Service

Public Abstract Void Service (ServletRequest Request, ServletRESPONSE

Response) Throws ServleTexception, IOException;

This is an abstract way. When you expand this class, in order to perform a network request, you have to execute it.

Nine, servletinputstream class / R

Definition / R

Public Abstract Class ServletInputStream Extends InputStream

This class defines the input stream for reading the request information of the client. This is an abstract class provided by a servlet engine. A servlet obtains an instructions for a servletinputStream object by using the ServletRequest interface.

Subclasses of this class must provide a way to read information about information from the InputStream interface.

method

1, Readline

Public int ready (Byte [] B, int off, int LEN)..

From the specified offset from the input stream, the byte of the specified length is read into the specified array. If the content of all requests of the line has been read, this read process will end. If you have encountered a new line, the first character of the new line will also be read into the array.

Ten, servletoutputstream class / R

Definition / R

Public Abstract Class ServletOutputStream Extends OutputStream

This is an abstract class that is used by the servlet engine. The servlet obtains an instructions for the object of one of this type by using the use of the ServletResponse interface. With this output stream, data can be returned to the client.

Subclasses of this class must provide a method of writing to the OutputStream interface to the information.

In this interface, when a refresh or closing method is called. All data buffers will be sent to the client, that is, the response is submitted. Note that when you close this type of object, you don't have to turn off the hidden Socket stream.

method

1, Print

Public void print (string s) throws oException;

Public Void Print (Boolean B) THROWS IOException;

Public Void Print (Char C) THROWS IOException; Public Void Print (INT I) Throws oException;

Public Void Print (long L) THROWS IOEXCEPTION;

Public void print (float f) throws oException;

Public Void Print (Double D) THROWS IOEXCEPTION;

Output variables into the output stream

2, Println

Public voidprintln () throws oException;

Public void println (string s) throws oException;

Public void println (Boolean B) THROWS IOEXCEPTION;

Public void Println (Char C) Throws oException;

Public Void Println (INT I) Throws oException;

Public Void Println (Long L) THROWS IOEXCEPTION;

Public void println (float f) throws oException;

Public void println (double d) throws oException;

Output variables into the output stream and add a carriage return / R

Eleven, ServletException class / R

Definition / R

Public Class ServleTexception Extends Exception

An exception thrown when the servlet encounters problems.

Constructor

Public servletexception ();

Public servleTexception (String Message);

Public servletexception (String Message, Throwable Cause);

Public servletexception (throwable cause);

Construct a new servletException, if this constructor includes a throwable parameter, this Throwable object will be used as a reason why it may throw this exception.

method

1, getrootcause

Public throwable getrootcause ();

This method will return this reason if it is configured, this method will return this, otherwise it returns an null value.

Twelve, UnavailableException class / R

Definition / R

Public Class UnavailableException Extends ServletException

Whether a servlet is permanently or temporarily invalid, this exception will be thrown. The servlet will record this exception and the corresponding measures to be taken by the Servlet Engine.

The temporary invalid means that the servlet cannot handle the request due to a temporary issue at a certain time. For example, a service (possibly a database) in another different application layer cannot be used. This issue may correct or need other corrective actions.

Permanent invalid means that this servlet will not be able to handle the client's request unless the administrator takes measures. For example, this servlet configuration information is lost or the state of servlet is destroyed.

The Servlet engine can safely handle these two exceptions, but the normal handling of temporary invalidation allows the servlet engine to be more robust. Special, at this time, the request for servlet is just blocked (or being extended) for a while, which is obviously more scientific than the request before the service is restarted.

Constructor

Public UnavailableException (Servlet Servlet, String Message); Public UnavailableException (Int Seconds, Servlet Servlet,

String message;

Constructs a new exception containing the specified description information. If this constructor has a parameter for the number of seconds, it will give the servlet to process the estimated time can be resrelected. If this parameter is not included, this means that this servlet is permanent.

method

1, GetServlet

Public servlet getServlet ();

Returns the report invalid servlet. This is used by the servlet engine to identify the affected servlet.

2, getunavailaseconds

Public int getunavailableseconds ();

Returns the timeless time of the servlet, if this servlet is permanent, return -1.

3, ISPERMANENT

Public boolean ispermanent ();

If this servlet is permanently invalid, return to the Boolean TRUE, indicating some management actions to make this servlet.

Java Servlet API Description Document (2.1A) (3)

Software package: javax.servlet.http

The interface contained: httpservletRequest; httpsession; httpsessionbindingListener; httpsessionContext.

The class contained: cookie; httpservlet; httpsessionBindingEvent; httputils.

First, HTTPSERVLETREQUEST interface

definition/

Public Interface HttpservletRequest Extends ServletRequest;

Used to process request information for the HTTP format of the 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 domain, this value 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)

This method returns -1 if this request header is not exist.

5, GetHeadernames

Public Enumeration GetHeadernames ();

This method returns a list of String objects that reflect all the header domain 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 getInetre (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 this request to use the HTTP method (for example: Get, Post, PUT)

8, getpathinfo

Public string getpathinfo ();

This method returns an additional path information of the request URL after the servlet path of this request. 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, this information is used to make HTTP user arguments.

If there is no username message in the request, this method returns a null value.

12, getRequestedSessionIDID

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 ();

The part of the requested resource is 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 calling 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, IsRequestedSessionIndiDValid

Public Boolean isRequestedSessionIdvalid ();

This method checks the session that is associated with this request is currently not 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 it returns false.

18, IsRequestedSessionIDFromurl

Public Boolean isRequestedSessionIDFromurl ();

If this request is provided by part of the URL of the client, 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

Describe an HTTP response that returns to the client. This interface allows the servlet programmers to utilize the header information specified by the HTTP protocol.

Member variables

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_persManently = 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 = 403;

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_ENTINTITY_TOO_LARGE = 413;

Public static final int sc_request_uri_too_long = 414;

Public Static Final Int SC_UNUNSUNSUPPORTED_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 production status code is defined by http / 1.1.

method

1, AddCookie

Public void addcookie (cookie cookie);

Add 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 (String Name);

Check if the specified response header is set.

3, EncoderedirectURL

Public String EncoderedirectURL (String URL);

Code 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);

Code 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) throws oException;

Public Void Senderror (int Statuscode, String Message) Throws

IOEXCEPTION;

Send an error response to the client with a given status code. 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 oewception;

Use a given path to issue a temporary steering response (SC_MOVED_TEMPORARILY) to the client. 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 exact intensity of the 1970-1-1 days (GMT). If the response head has been set, the new value will overwrite the current value.

8, SetHeader

Public void sethead (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 (String name, int value);

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 statuscode);

This method sets the status code of the response. If the status code has been set, the new value will overwrite the current value.

Several methods will be canceled /

11, EncoderedirectURL

Public String EncodeRedirectURL (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 statscode, 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, httpsession interface

definition/

Public Interface HttpSession

This interface is used by the servlet engine to achieve both HTTP clients and HTTP sessions. 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 ();

Returns the time to establish the session, this time is expressed as the number of milliseconds 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 getlastaccessedtime ();

Returns the time for the client issues 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 ();

Return to a second, this second indicates 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 ();

Returns the name of all the 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 ();

Returns 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);

Bind the 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. If you do not find the object of the binding name, this method does nothing. 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);

Set a second number, this second indicates that the client maintains the longest time for 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.

Fourth, httpsessionBindingListener interface

definition/

Public interface httpsessionBindingListener

This object is added to the session of HTTP, and this interface will be notified that there is no object being bind 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 canceled from the session. When the HttpSession.RemoveValue method is called, the Servlet engine should call this method.

5. httpsessionContext interface

definition/

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 session);

It was used to return Session related to this session ID. Now return null values.

2, GetIDS

Public Enumeration GetIDS ();

The list used to return all session IDs in this environment. Now return a list of empty.

Sixth, cookie class /

definition/

Public Class Cookie IMPLEments CLONEABLE

This class describes a cookie, and the definition of cookies You can refer to the RFC 2109 with reference to the Netscape Communications Corporation. Constructor

Public cookie (String name, string value);

Use a Name-value to define a cookie. 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 the prefix of all URL paths valid for this cookie, if not defined, return null values.

6, GetSecure

Public Boolean getsecure ();

If this cookie is only returned by secure channel transfer, 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 (String purpose);

If a user submits this cookie to another user, you must describe this cookie's purpose through 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);

It is 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; 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);

Set the version number of the cookie

Seven, httpservlet class /

definition/

Public class httpservlet 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 Void Dodelete (HttpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

Call is 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;

The service method of this class is called 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;

The service method of this class is called 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 dooptions (httpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

Call is called by this class to process an HTTP Option operation. This operation automatically decides which HTTP method to support. For example, a servlet writes a subclass of HTTPSERVLET and overloads the Doget method, and DOOPTION will return the head below:

Allow: Get, Head, Trace, Options You do not need to overload this method.

5, dopost

Protected Void Dopost (httpservletRequest Request,

HttpservletResponse response) Throws servletexception,

IOEXCEPTION;

The service method of this class is called 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;

Call is called by this class 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 response) Throws servletexception,

IOEXCEPTION;

Call is called by this class 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's HTTP-SPECIFIC solution that assigns other methods for supporting this request to support this class.

When you develop servlets, in most cases you don't have to overload this method.

Eight, httpsessionBindingEvent class /

definition/

Public Class HttpSessionBindingEvent Extends EventObject

This event is connected to HTTPSessionBindingListener when listening to the HTTPSession occurs and cancels. This may be a result of session being terminated or identified. The event source is httpsession.putValue or httpsession.removevalue.

Constructor

Public httpsessionBindingEvent (httpsession session, string name);

Construct a new HttpSessionBindInGevent by causing the session of this event and a binding or cancel the binding object name.

method

1, getname

Public string getname ();

Returns the name of the object that occurs and cancels the binding.

2, GetSession

Public httpsession getsession ();

Returns the name of the Session that occurs and cancels the binding.

Nine, httputils /

definition/

Public class httputils

Collect the static effective way to use the HTTP Servlet.

method

1, GetRequestURL

Public Static StringBuffer GetRequestURL (httpservletRequest

REQUEST;

Reconstruct the client on the server to establish the URL of the request. 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);

Parked a stream of data that contains 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);

Parrse a query string and create 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.

Java Servlet API Description Document (2.1A) (4)

Glossary / R

BYTECODE

B3 code: The machine code generated by the Java compiler and Java interpreter.

cookie

The data established by the web server, which is stored on the user's computer, providing a web site to track the user's parameters and store methods on the user's own hard drive.

HTTP

Hypertext transfer protocol. A request response protocol is used to connect the WWW server to the client browser to transfer the HTML page.

Input flow object / r

An object, is defined by the servletinputStream class, and is used by servlet to read the request from the client. Mapping / R

One pair of URLs that return data by servlet instances and servlets, for example, Helloservlet and /Hello/index.html.

Output flow object / r

An object, defined by the servletoutstream Class class, is used by servlet to return data to the client.

Request Dispatcher Object

An object defined by the RequestDispatcher interface to receive requests from the client and send it to other resources available on the web server (such as servlet, CGI, HTML files, or JSP files).

Sandboxed servlet

Servlet running under a security constraint.

servlet

A small, a platform-independent, a Java program without a graphical user interface. It can expand the functionality of Web services in many ways.

Servlet Configuration Object

A SERVLETCONFIG interface defines an object to configure a servlet.

Servlet Context Object

A object defined by the servletContext interface. Give the servlet information about the servlet engine.

Servlet Engine / R

An environment created by the web server provider, allows servlets to be run on a specific web server.

Servlet request object

An object defined by the servletRequest interface allows the servlet to get the data requested by the client.

Servlet Response Object

An object defined by the servletResponse interface allows the servlet to respond.

Servlet Runner

The Sun.Servlet.http.httpserver process in the Java Servlet Developer's Kit (JSDK) is made by servlets.

Session tracking

In a web application, identify a continuous unique request from the same client.

SSL

Encrypted socket protocol layer. A security protocol that swaps key and encrypted data on client browsers and servers on your iTernet.

URI

Unified resource logo. Define an Internet address, it is a URL superchard.

URL

Unified resource path. This address defines the route to files reached on a WWW, which is usually composed of protocol prefix, domain name, directory name, and file name.

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

New Post(0)