response.sendRedirect到ftp上一个文件的中文问题

irbis 2010-03-02 11:22:11
想法,通过JSP页面查询要下载的文件,路径在ftp服务器上。

不知道如何跳转,用response.sendRedirect文件名中文乱码,encode后虽然能下载,但是保存的文件名还是无法还原到正常的中文。

谁有什么好办法?
...全文
178 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
扁鵲東南飛 2010-03-02
  • 打赏
  • 举报
回复
引用 3 楼 muhaitang 的回复:
String url="test.jsp?name=乱码&pwd=1111";
url=new String(url.getBytes("GBK"),"ISO8859_1");
response.sendRedirect(url);
在调用response.sendRedirect之前要先转换成ISO8859_1编码


感觉这样可以,不知道行不行,不行的话,你去转其他的编码方式。
海棠无香1998 2010-03-02
  • 打赏
  • 举报
回复
String url="test.jsp?name=乱码&pwd=1111";
url=new String(url.getBytes("GBK"),"ISO8859_1");
response.sendRedirect(url);
在调用response.sendRedirect之前要先转换成ISO8859_1编码
exezdl 2010-03-02
  • 打赏
  • 举报
回复
用XMLHttp下载
牛叔 2010-03-02
  • 打赏
  • 举报
回复
网上搜个例子吧
看下就行了
irbis 2010-03-02
  • 打赏
  • 举报
回复
当然,由于转向地址在不同主机上,因此没办法用RequestDispatcher.forward()
irbis 2010-03-02
  • 打赏
  • 举报
回复
其实是要redirect到ftp://test:test@ftp.xxx.com/中文文件名.rar这样的路径

试过了,重新编码或不编码都找不到文件,只有用URLEncoder.encode才能正常找到文件,当然同时文件名也变成一堆%
soulx 2010-03-02
  • 打赏
  • 举报
回复

response.setContentType("application/octet-stream;charset=UTF-8");
String filename = new String(filename.getBytes("GB2312"), "ISO-8859-1");
response.setHeader("Content-Disposition","inline; filename="+filename);
bbb332 2010-03-02
  • 打赏
  • 举报
回复
场合:页面本身有中文的时候
解决办法:servlet:resp.setContentType("text/html;charset=gbk");
Jsp: <%@ page contentType="text/html;charset=gb2312"%>
注意:一定要写在PrintWriter out = resp.getWriter();之前


场合:解决get方式乱码问题:
解决办法:修改server.xml URIEncoding="GBK"
场合:解决post方式提交内容的乱码
解决办法:request.setCharacterEncoding("GBK");
注意:一定要写在存取第一个参数之前
不要调用response.setCharacterEncoding("GBK");


场合:<jsp:param name="user" value="<%=s%>"/>,url地址包含中文参数
解决办法:<%request.setCharacterEncoding("GBK");%>
Overview Package Class Tree Deprecated Index Help PREV NEXT FRAMES NO FRAMES A B C D E F G H I J L P R S U V -------------------------------------------------------------------------------- A addCookie(Cookie) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to call addCookie(Cookie cookie) on the wrapped response object. addCookie(Cookie) - Method in interface javax.servlet.http.HttpServletResponse Adds the specified cookie to the response. addDateHeader(String, long) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to call addDateHeader(String name, long date) on the wrapped response object. addDateHeader(String, long) - Method in interface javax.servlet.http.HttpServletResponse Adds a response header with the given name and date-value. addHeader(String, String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to return addHeader(String name, String value) on the wrapped response object. addHeader(String, String) - Method in interface javax.servlet.http.HttpServletResponse Adds a response header with the given name and value. addIntHeader(String, int) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to call addIntHeader(String name, int value) on the wrapped response object. addIntHeader(String, int) - Method in interface javax.servlet.http.HttpServletResponse Adds a response header with the given name and integer value. attributeAdded(HttpSessionBindingEvent) - Method in interface javax.servlet.http.HttpSessionAttributeListener Notification that an attribute has been added to a session. attributeAdded(ServletContextAttributeEvent) - Method in interface javax.servlet.ServletContextAttributeListener Notification that a new attribute was added to the servlet context. attributeAdded(ServletRequestAttributeEvent) - Method in interface javax.servlet.ServletRequestAttributeListener Notification that a new attribute was added to the servlet request. attributeRemoved(HttpSessionBindingEvent) - Method in interface javax.servlet.http.HttpSessionAttributeListener Notification that an attribute has been removed from a session. attributeRemoved(ServletContextAttributeEvent) - Method in interface javax.servlet.ServletContextAttributeListener Notification that an existing attribute has been removed from the servlet context. attributeRemoved(ServletRequestAttributeEvent) - Method in interface javax.servlet.ServletRequestAttributeListener Notification that a new attribute was removed from the servlet request. attributeReplaced(HttpSessionBindingEvent) - Method in interface javax.servlet.http.HttpSessionAttributeListener Notification that an attribute has been replaced in a session. attributeReplaced(ServletContextAttributeEvent) - Method in interface javax.servlet.ServletContextAttributeListener Notification that an attribute on the servlet context has been replaced. attributeReplaced(ServletRequestAttributeEvent) - Method in interface javax.servlet.ServletRequestAttributeListener Notification that an attribute was replaced on the servlet request. -------------------------------------------------------------------------------- B BASIC_AUTH - Static variable in interface javax.servlet.http.HttpServletRequest String identifier for Basic authentication. -------------------------------------------------------------------------------- C CLIENT_CERT_AUTH - Static variable in interface javax.servlet.http.HttpServletRequest String identifier for Client Certificate authentication. clone() - Method in class javax.servlet.http.Cookie Overrides the standard java.lang.Object.clone method to return a copy of this cookie. containsHeader(String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to call containsHeader(String name) on the wrapped response object. containsHeader(String) - Method in interface javax.servlet.http.HttpServletResponse Returns a boolean indicating whether the named response header has already been set. contextDestroyed(ServletContextEvent) - Method in interface javax.servlet.ServletContextListener Notification that the servlet context is about to be shut down. contextInitialized(ServletContextEvent) - Method in interface javax.servlet.ServletContextListener Notification that the web application initialization process is starting. Cookie - class javax.servlet.http.Cookie. Creates a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server. Cookie(String, String) - Constructor for class javax.servlet.http.Cookie Constructs a cookie with a specified name and value. -------------------------------------------------------------------------------- D destroy() - Method in interface javax.servlet.Filter Called by the web container to indicate to a filter that it is being taken out of service. destroy() - Method in interface javax.servlet.Servlet Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. destroy() - Method in class javax.servlet.GenericServlet Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. DIGEST_AUTH - Static variable in interface javax.servlet.http.HttpServletRequest String identifier for Digest authentication. doDelete(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Called by the server (via the service method) to allow a servlet to handle a DELETE request. doFilter(ServletRequest, ServletResponse) - Method in interface javax.servlet.FilterChain Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked. doFilter(ServletRequest, ServletResponse, FilterChain) - Method in interface javax.servlet.Filter The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. doGet(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Called by the server (via the service method) to allow a servlet to handle a GET request. doHead(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Receives an HTTP HEAD request from the protected service method and handles the request. doOptions(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Called by the server (via the service method) to allow a servlet to handle a OPTIONS request. doPost(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Called by the server (via the service method) to allow a servlet to handle a POST request. doPut(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Called by the server (via the service method) to allow a servlet to handle a PUT request. doTrace(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Called by the server (via the service method) to allow a servlet to handle a TRACE request. -------------------------------------------------------------------------------- E encodeRedirectUrl(String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to return encodeRedirectUrl(String url) on the wrapped response object. encodeRedirectUrl(String) - Method in interface javax.servlet.http.HttpServletResponse Deprecated. As of version 2.1, use encodeRedirectURL(String url) instead encodeRedirectURL(String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to return encodeRedirectURL(String url) on the wrapped response object. encodeRedirectURL(String) - Method in interface javax.servlet.http.HttpServletResponse Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged. encodeUrl(String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to call encodeUrl(String url) on the wrapped response object. encodeUrl(String) - Method in interface javax.servlet.http.HttpServletResponse Deprecated. As of version 2.1, use encodeURL(String url) instead encodeURL(String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to call encodeURL(String url) on the wrapped response object. encodeURL(String) - Method in interface javax.servlet.http.HttpServletResponse Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged. -------------------------------------------------------------------------------- F Filter - interface javax.servlet.Filter. A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both. Filters perform filtering in the doFilter method. FilterChain - interface javax.servlet.FilterChain. A FilterChain is an object provided by the servlet container to the developer giving a view into the invocation chain of a filtered request for a resource. FilterConfig - interface javax.servlet.FilterConfig. A filter configuration object used by a servlet container to pass information to a filter during initialization. flushBuffer() - Method in interface javax.servlet.ServletResponse Forces any content in the buffer to be written to the client. flushBuffer() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to call flushBuffer() on the wrapped response object. FORM_AUTH - Static variable in interface javax.servlet.http.HttpServletRequest String identifier for Form authentication. forward(ServletRequest, ServletResponse) - Method in interface javax.servlet.RequestDispatcher Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. -------------------------------------------------------------------------------- G GenericServlet - class javax.servlet.GenericServlet. Defines a generic, protocol-independent servlet. GenericServlet() - Constructor for class javax.servlet.GenericServlet Does nothing. getAttribute(String) - Method in interface javax.servlet.ServletContext Returns the servlet container attribute with the given name, or null if there is no attribute by that name. getAttribute(String) - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to call getAttribute(String name) on the wrapped request object. getAttribute(String) - Method in interface javax.servlet.ServletRequest Returns the value of the named attribute as an Object, or null if no attribute of the given name exists. getAttribute(String) - Method in interface javax.servlet.http.HttpSession Returns the object bound with the specified name in this session, or null if no object is bound under the name. getAttributeNames() - Method in interface javax.servlet.ServletContext Returns an Enumeration containing the attribute names available within this servlet context. getAttributeNames() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getAttributeNames() on the wrapped request object. getAttributeNames() - Method in interface javax.servlet.ServletRequest Returns an Enumeration containing the names of the attributes available to this request. getAttributeNames() - Method in interface javax.servlet.http.HttpSession Returns an Enumeration of String objects containing the names of all the objects bound to this session. getAuthType() - Method in interface javax.servlet.http.HttpServletRequest Returns the name of the authentication scheme used to protect the servlet. getAuthType() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getAuthType() on the wrapped request object. getBufferSize() - Method in interface javax.servlet.ServletResponse Returns the actual buffer size used for the response. getBufferSize() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to return getBufferSize() on the wrapped response object. getCharacterEncoding() - Method in interface javax.servlet.ServletResponse Returns the name of the character encoding (MIME charset) used for the body sent in this response. getCharacterEncoding() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getCharacterEncoding() on the wrapped request object. getCharacterEncoding() - Method in interface javax.servlet.ServletRequest Returns the name of the character encoding used in the body of this request. getCharacterEncoding() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to return getCharacterEncoding() on the wrapped response object. getComment() - Method in class javax.servlet.http.Cookie Returns the comment describing the purpose of this cookie, or null if the cookie has no comment. getContentLength() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getContentLength() on the wrapped request object. getContentLength() - Method in interface javax.servlet.ServletRequest Returns the length, in bytes, of the request body and made available by the input stream, or -1 if the length is not known. getContentType() - Method in interface javax.servlet.ServletResponse Returns the content type used for the MIME body sent in this response. getContentType() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getContentType() on the wrapped request object. getContentType() - Method in interface javax.servlet.ServletRequest Returns the MIME type of the body of the request, or null if the type is not known. getContentType() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to return getContentType() on the wrapped response object. getContext(String) - Method in interface javax.servlet.ServletContext Returns a ServletContext object that corresponds to a specified URL on the server. getContextPath() - Method in interface javax.servlet.http.HttpServletRequest Returns the portion of the request URI that indicates the context of the request. getContextPath() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getContextPath() on the wrapped request object. getCookies() - Method in interface javax.servlet.http.HttpServletRequest Returns an array containing all of the Cookie objects the client sent with this request. getCookies() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getCookies() on the wrapped request object. getCreationTime() - Method in interface javax.servlet.http.HttpSession Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT. getDateHeader(String) - Method in interface javax.servlet.http.HttpServletRequest Returns the value of the specified request header as a long value that represents a Date object. getDateHeader(String) - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getDateHeader(String name) on the wrapped request object. getDomain() - Method in class javax.servlet.http.Cookie Returns the domain name set for this cookie. getFilterName() - Method in interface javax.servlet.FilterConfig Returns the filter-name of this filter as defined in the deployment descriptor. getHeader(String) - Method in interface javax.servlet.http.HttpServletRequest Returns the value of the specified request header as a String. getHeader(String) - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getHeader(String name) on the wrapped request object. getHeaderNames() - Method in interface javax.servlet.http.HttpServletRequest Returns an enumeration of all the header names this request contains. getHeaderNames() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getHeaderNames() on the wrapped request object. getHeaders(String) - Method in interface javax.servlet.http.HttpServletRequest Returns all the values of the specified request header as an Enumeration of String objects. getHeaders(String) - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getHeaders(String name) on the wrapped request object. getId() - Method in interface javax.servlet.http.HttpSession Returns a string containing the unique identifier assigned to this session. getIds() - Method in interface javax.servlet.http.HttpSessionContext Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return an empty Enumeration and will be removed in a future version of this API. getInitParameter(String) - Method in interface javax.servlet.FilterConfig Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. getInitParameter(String) - Method in interface javax.servlet.ServletConfig Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. getInitParameter(String) - Method in interface javax.servlet.ServletContext Returns a String containing the value of the named context-wide initialization parameter, or null if the parameter does not exist. getInitParameter(String) - Method in class javax.servlet.GenericServlet Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist. getInitParameterNames() - Method in interface javax.servlet.FilterConfig Returns the names of the filter's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the filter has no initialization parameters. getInitParameterNames() - Method in interface javax.servlet.ServletConfig Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters. getInitParameterNames() - Method in interface javax.servlet.ServletContext Returns the names of the context's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the context has no initialization parameters. getInitParameterNames() - Method in class javax.servlet.GenericServlet Returns the names of the servlet's initialization parameters as an Enumeration of String objects, or an empty Enumeration if the servlet has no initialization parameters. getInputStream() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getInputStream() on the wrapped request object. getInputStream() - Method in interface javax.servlet.ServletRequest Retrieves the body of the request as binary data using a ServletInputStream. getIntHeader(String) - Method in interface javax.servlet.http.HttpServletRequest Returns the value of the specified request header as an int. getIntHeader(String) - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getIntHeader(String name) on the wrapped request object. getLastAccessedTime() - Method in interface javax.servlet.http.HttpSession Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT, and marked by the time the container received the request. getLastModified(HttpServletRequest) - Method in class javax.servlet.http.HttpServlet Returns the time the HttpServletRequest object was last modified, in milliseconds since midnight January 1, 1970 GMT. getLocalAddr() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getLocalAddr() on the wrapped request object. getLocalAddr() - Method in interface javax.servlet.ServletRequest Returns the Internet Protocol (IP) address of the interface on which the request was received. getLocale() - Method in interface javax.servlet.ServletResponse Returns the locale specified for this response using the ServletResponse.setLocale(java.util.Locale) method. getLocale() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getLocale() on the wrapped request object. getLocale() - Method in interface javax.servlet.ServletRequest Returns the preferred Locale that the client will accept content in, based on the Accept-Language header. getLocale() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to return getLocale() on the wrapped response object. getLocales() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getLocales() on the wrapped request object. getLocales() - Method in interface javax.servlet.ServletRequest Returns an Enumeration of Locale objects indicating, in decreasing order starting with the preferred locale, the locales that are acceptable to the client based on the Accept-Language header. getLocalName() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getLocalName() on the wrapped request object. getLocalName() - Method in interface javax.servlet.ServletRequest Returns the host name of the Internet Protocol (IP) interface on which the request was received. getLocalPort() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getLocalPort() on the wrapped request object. getLocalPort() - Method in interface javax.servlet.ServletRequest Returns the Internet Protocol (IP) port number of the interface on which the request was received. getMajorVersion() - Method in interface javax.servlet.ServletContext Returns the major version of the Java Servlet API that this servlet container supports. getMaxAge() - Method in class javax.servlet.http.Cookie Returns the maximum age of the cookie, specified in seconds, By default, -1 indicating the cookie will persist until browser shutdown. getMaxInactiveInterval() - Method in interface javax.servlet.http.HttpSession Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. getMethod() - Method in interface javax.servlet.http.HttpServletRequest Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. getMethod() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getMethod() on the wrapped request object. getMimeType(String) - Method in interface javax.servlet.ServletContext Returns the MIME type of the specified file, or null if the MIME type is not known. getMinorVersion() - Method in interface javax.servlet.ServletContext Returns the minor version of the Servlet API that this servlet container supports. getName() - Method in class javax.servlet.ServletContextAttributeEvent Return the name of the attribute that changed on the ServletContext. getName() - Method in class javax.servlet.ServletRequestAttributeEvent Return the name of the attribute that changed on the ServletRequest getName() - Method in class javax.servlet.http.HttpSessionBindingEvent Returns the name with which the attribute is bound to or unbound from the session. getName() - Method in class javax.servlet.http.Cookie Returns the name of the cookie. getNamedDispatcher(String) - Method in interface javax.servlet.ServletContext Returns a RequestDispatcher object that acts as a wrapper for the named servlet. getOutputStream() - Method in interface javax.servlet.ServletResponse Returns a ServletOutputStream suitable for writing binary data in the response. getOutputStream() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to return getOutputStream() on the wrapped response object. getParameter(String) - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getParameter(String name) on the wrapped request object. getParameter(String) - Method in interface javax.servlet.ServletRequest Returns the value of a request parameter as a String, or null if the parameter does not exist. getParameterMap() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getParameterMap() on the wrapped request object. getParameterMap() - Method in interface javax.servlet.ServletRequest Returns a java.util.Map of the parameters of this request. getParameterNames() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getParameterNames() on the wrapped request object. getParameterNames() - Method in interface javax.servlet.ServletRequest Returns an Enumeration of String objects containing the names of the parameters contained in this request. getParameterValues(String) - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getParameterValues(String name) on the wrapped request object. getParameterValues(String) - Method in interface javax.servlet.ServletRequest Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist. getPath() - Method in class javax.servlet.http.Cookie Returns the path on the server to which the browser returns this cookie. getPathInfo() - Method in interface javax.servlet.http.HttpServletRequest Returns any extra path information associated with the URL the client sent when it made this request. getPathInfo() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getPathInfo() on the wrapped request object. getPathTranslated() - Method in interface javax.servlet.http.HttpServletRequest Returns any extra path information after the servlet name but before the query string, and translates it to a real path. getPathTranslated() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getPathTranslated() on the wrapped request object. getProtocol() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getProtocol() on the wrapped request object. getProtocol() - Method in interface javax.servlet.ServletRequest Returns the name and version of the protocol the request uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1. getQueryString() - Method in interface javax.servlet.http.HttpServletRequest Returns the query string that is contained in the request URL after the path. getQueryString() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getQueryString() on the wrapped request object. getReader() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getReader() on the wrapped request object. getReader() - Method in interface javax.servlet.ServletRequest Retrieves the body of the request as character data using a BufferedReader. getRealPath(String) - Method in interface javax.servlet.ServletContext Returns a String containing the real path for a given virtual path. getRealPath(String) - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getRealPath(String path) on the wrapped request object. getRealPath(String) - Method in interface javax.servlet.ServletRequest Deprecated. As of Version 2.1 of the Java Servlet API, use ServletContext.getRealPath(java.lang.String) instead. getRemoteAddr() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getRemoteAddr() on the wrapped request object. getRemoteAddr() - Method in interface javax.servlet.ServletRequest Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. getRemoteHost() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getRemoteHost() on the wrapped request object. getRemoteHost() - Method in interface javax.servlet.ServletRequest Returns the fully qualified name of the client or the last proxy that sent the request. getRemotePort() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getRemotePort() on the wrapped request object. getRemotePort() - Method in interface javax.servlet.ServletRequest Returns the Internet Protocol (IP) source port of the client or last proxy that sent the request. getRemoteUser() - Method in interface javax.servlet.http.HttpServletRequest Returns the login of the user making this request, if the user has been authenticated, or null if the user has not been authenticated. getRemoteUser() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getRemoteUser() on the wrapped request object. getRequest() - Method in class javax.servlet.ServletRequestWrapper Return the wrapped request object. getRequestDispatcher(String) - Method in interface javax.servlet.ServletContext Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. getRequestDispatcher(String) - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object. getRequestDispatcher(String) - Method in interface javax.servlet.ServletRequest Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. getRequestedSessionId() - Method in interface javax.servlet.http.HttpServletRequest Returns the session ID specified by the client. getRequestedSessionId() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getRequestedSessionId() on the wrapped request object. getRequestURI() - Method in interface javax.servlet.http.HttpServletRequest Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. getRequestURI() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getRequestURI() on the wrapped request object. getRequestURL() - Method in interface javax.servlet.http.HttpServletRequest Reconstructs the URL the client used to make the request. getRequestURL() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getRequestURL() on the wrapped request object. getRequestURL(HttpServletRequest) - Static method in class javax.servlet.http.HttpUtils Deprecated. Reconstructs the URL the client used to make the request, using information in the HttpServletRequest object. getResource(String) - Method in interface javax.servlet.ServletContext Returns a URL to the resource that is mapped to a specified path. getResourceAsStream(String) - Method in interface javax.servlet.ServletContext Returns the resource located at the named path as an InputStream object. getResourcePaths(String) - Method in interface javax.servlet.ServletContext Returns a directory-like listing of all the paths to resources within the web application whose longest sub-path matches the supplied path argument. getResponse() - Method in class javax.servlet.ServletResponseWrapper Return the wrapped ServletResponse object. getRootCause() - Method in class javax.servlet.ServletException Returns the exception that caused this servlet exception. getScheme() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getScheme() on the wrapped request object. getScheme() - Method in interface javax.servlet.ServletRequest Returns the name of the scheme used to make this request, for example, http, https, or ftp. getSecure() - Method in class javax.servlet.http.Cookie Returns true if the browser is sending cookies only over a secure protocol, or false if the browser can send cookies using any protocol. getServerInfo() - Method in interface javax.servlet.ServletContext Returns the name and version of the servlet container on which the servlet is running. getServerName() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getServerName() on the wrapped request object. getServerName() - Method in interface javax.servlet.ServletRequest Returns the host name of the server to which the request was sent. getServerPort() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return getServerPort() on the wrapped request object. getServerPort() - Method in interface javax.servlet.ServletRequest Returns the port number to which the request was sent. getServlet() - Method in class javax.servlet.UnavailableException Deprecated. As of Java Servlet API 2.2, with no replacement. Returns the servlet that is reporting its unavailability. getServlet(String) - Method in interface javax.servlet.ServletContext Deprecated. As of Java Servlet API 2.1, with no direct replacement. This method was originally defined to retrieve a servlet from a ServletContext. In this version, this method always returns null and remains only to preserve binary compatibility. This method will be permanently removed in a future version of the Java Servlet API. In lieu of this method, servlets can share information using the ServletContext class and can perform shared business logic by invoking methods on common non-servlet classes. getServletConfig() - Method in interface javax.servlet.Servlet Returns a ServletConfig object, which contains initialization and startup parameters for this servlet. getServletConfig() - Method in class javax.servlet.GenericServlet Returns this servlet's ServletConfig object. getServletContext() - Method in class javax.servlet.ServletRequestEvent Returns the ServletContext of this web application. getServletContext() - Method in interface javax.servlet.FilterConfig Returns a reference to the ServletContext in which the caller is executing. getServletContext() - Method in interface javax.servlet.ServletConfig Returns a reference to the ServletContext in which the caller is executing. getServletContext() - Method in class javax.servlet.ServletContextEvent Return the ServletContext that changed. getServletContext() - Method in class javax.servlet.GenericServlet Returns a reference to the ServletContext in which this servlet is running. getServletContext() - Method in interface javax.servlet.http.HttpSession Returns the ServletContext to which this session belongs. getServletContextName() - Method in interface javax.servlet.ServletContext Returns the name of this web application corresponding to this ServletContext as specified in the deployment descriptor for this web application by the display-name element. getServletInfo() - Method in interface javax.servlet.Servlet Returns information about the servlet, such as author, version, and copyright. getServletInfo() - Method in class javax.servlet.GenericServlet Returns information about the servlet, such as author, version, and copyright. getServletName() - Method in interface javax.servlet.ServletConfig Returns the name of this servlet instance. getServletName() - Method in class javax.servlet.GenericServlet Returns the name of this servlet instance. getServletNames() - Method in interface javax.servlet.ServletContext Deprecated. As of Java Servlet API 2.1, with no replacement. This method was originally defined to return an Enumeration of all the servlet names known to this context. In this version, this method always returns an empty Enumeration and remains only to preserve binary compatibility. This method will be permanently removed in a future version of the Java Servlet API. getServletPath() - Method in interface javax.servlet.http.HttpServletRequest Returns the part of this request's URL that calls the servlet. getServletPath() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getServletPath() on the wrapped request object. getServletRequest() - Method in class javax.servlet.ServletRequestEvent Returns the ServletRequest that is changing. getServlets() - Method in interface javax.servlet.ServletContext Deprecated. As of Java Servlet API 2.0, with no replacement. This method was originally defined to return an Enumeration of all the servlets known to this servlet context. In this version, this method always returns an empty enumeration and remains only to preserve binary compatibility. This method will be permanently removed in a future version of the Java Servlet API. getSession() - Method in class javax.servlet.http.HttpSessionEvent Return the session that changed. getSession() - Method in class javax.servlet.http.HttpSessionBindingEvent Return the session that changed. getSession() - Method in interface javax.servlet.http.HttpServletRequest Returns the current session associated with this request, or if the request does not have a session, creates one. getSession() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getSession() on the wrapped request object. getSession(boolean) - Method in interface javax.servlet.http.HttpServletRequest Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session. getSession(boolean) - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getSession(boolean create) on the wrapped request object. getSession(String) - Method in interface javax.servlet.http.HttpSessionContext Deprecated. As of Java Servlet API 2.1 with no replacement. This method must return null and will be removed in a future version of this API. getSessionContext() - Method in interface javax.servlet.http.HttpSession Deprecated. As of Version 2.1, this method is deprecated and has no replacement. It will be removed in a future version of the Java Servlet API. getUnavailableSeconds() - Method in class javax.servlet.UnavailableException Returns the number of seconds the servlet expects to be temporarily unavailable. getUserPrincipal() - Method in interface javax.servlet.http.HttpServletRequest Returns a java.security.Principal object containing the name of the current authenticated user. getUserPrincipal() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return getUserPrincipal() on the wrapped request object. getValue() - Method in class javax.servlet.ServletContextAttributeEvent Returns the value of the attribute that has been added, removed, or replaced. getValue() - Method in class javax.servlet.ServletRequestAttributeEvent Returns the value of the attribute that has been added, removed or replaced. getValue() - Method in class javax.servlet.http.HttpSessionBindingEvent Returns the value of the attribute that has been added, removed or replaced. getValue() - Method in class javax.servlet.http.Cookie Returns the value of the cookie. getValue(String) - Method in interface javax.servlet.http.HttpSession Deprecated. As of Version 2.2, this method is replaced by HttpSession.getAttribute(java.lang.String). getValueNames() - Method in interface javax.servlet.http.HttpSession Deprecated. As of Version 2.2, this method is replaced by HttpSession.getAttributeNames() getVersion() - Method in class javax.servlet.http.Cookie Returns the version of the protocol this cookie complies with. getWriter() - Method in interface javax.servlet.ServletResponse Returns a PrintWriter object that can send character text to the client. getWriter() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to return getWriter() on the wrapped response object. -------------------------------------------------------------------------------- H HttpServlet - class javax.servlet.http.HttpServlet. Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. HttpServlet() - Constructor for class javax.servlet.http.HttpServlet Does nothing, because this is an abstract class. HttpServletRequest - interface javax.servlet.http.HttpServletRequest. Extends the ServletRequest interface to provide request information for HTTP servlets. HttpServletRequestWrapper - class javax.servlet.http.HttpServletRequestWrapper. Provides a convenient implementation of the HttpServletRequest interface that can be subclassed by developers wishing to adapt the request to a Servlet. HttpServletRequestWrapper(HttpServletRequest) - Constructor for class javax.servlet.http.HttpServletRequestWrapper Constructs a request object wrapping the given request. HttpServletResponse - interface javax.servlet.http.HttpServletResponse. Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response. HttpServletResponseWrapper - class javax.servlet.http.HttpServletResponseWrapper. Provides a convenient implementation of the HttpServletResponse interface that can be subclassed by developers wishing to adapt the response from a Servlet. HttpServletResponseWrapper(HttpServletResponse) - Constructor for class javax.servlet.http.HttpServletResponseWrapper Constructs a response adaptor wrapping the given response. HttpSession - interface javax.servlet.http.HttpSession. Provides a way to identify a user across more than one page request or visit to a Web site and to store information about that user. HttpSessionActivationListener - interface javax.servlet.http.HttpSessionActivationListener. Objects that are bound to a session may listen to container events notifying them that sessions will be passivated and that session will be activated. HttpSessionAttributeListener - interface javax.servlet.http.HttpSessionAttributeListener. This listener interface can be implemented in order to get notifications of changes to the attribute lists of sessions within this web application. HttpSessionBindingEvent - class javax.servlet.http.HttpSessionBindingEvent. Events of this type are either sent to an object that implements HttpSessionBindingListener when it is bound or unbound from a session, or to a HttpSessionAttributeListener that has been configured in the deployment descriptor when any attribute is bound, unbound or replaced in a session. HttpSessionBindingEvent(HttpSession, String) - Constructor for class javax.servlet.http.HttpSessionBindingEvent Constructs an event that notifies an object that it has been bound to or unbound from a session. HttpSessionBindingEvent(HttpSession, String, Object) - Constructor for class javax.servlet.http.HttpSessionBindingEvent Constructs an event that notifies an object that it has been bound to or unbound from a session. HttpSessionBindingListener - interface javax.servlet.http.HttpSessionBindingListener. Causes an object to be notified when it is bound to or unbound from a session. HttpSessionContext - interface javax.servlet.http.HttpSessionContext. Deprecated. As of Java(tm) Servlet API 2.1 for security reasons, with no replacement. This interface will be removed in a future version of this API. HttpSessionEvent - class javax.servlet.http.HttpSessionEvent. This is the class representing event notifications for changes to sessions within a web application. HttpSessionEvent(HttpSession) - Constructor for class javax.servlet.http.HttpSessionEvent Construct a session event from the given source. HttpSessionListener - interface javax.servlet.http.HttpSessionListener. Implementations of this interface are notified of changes to the list of active sessions in a web application. HttpUtils - class javax.servlet.http.HttpUtils. Deprecated. As of Java(tm) Servlet API 2.3. These methods were only useful with the default encoding and have been moved to the request interfaces. HttpUtils() - Constructor for class javax.servlet.http.HttpUtils Deprecated. Constructs an empty HttpUtils object. -------------------------------------------------------------------------------- I include(ServletRequest, ServletResponse) - Method in interface javax.servlet.RequestDispatcher Includes the content of a resource (servlet, JSP page, HTML file) in the response. init() - Method in class javax.servlet.GenericServlet A convenience method which can be overridden so that there's no need to call super.init(config). init(FilterConfig) - Method in interface javax.servlet.Filter Called by the web container to indicate to a filter that it is being placed into service. init(ServletConfig) - Method in interface javax.servlet.Servlet Called by the servlet container to indicate to a servlet that the servlet is being placed into service. init(ServletConfig) - Method in class javax.servlet.GenericServlet Called by the servlet container to indicate to a servlet that the servlet is being placed into service. invalidate() - Method in interface javax.servlet.http.HttpSession Invalidates this session then unbinds any objects bound to it. isCommitted() - Method in interface javax.servlet.ServletResponse Returns a boolean indicating if the response has been committed. isCommitted() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to return isCommitted() on the wrapped response object. isNew() - Method in interface javax.servlet.http.HttpSession Returns true if the client does not yet know about the session or if the client chooses not to join the session. isPermanent() - Method in class javax.servlet.UnavailableException Returns a boolean indicating whether the servlet is permanently unavailable. isRequestedSessionIdFromCookie() - Method in interface javax.servlet.http.HttpServletRequest Checks whether the requested session ID came in as a cookie. isRequestedSessionIdFromCookie() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return isRequestedSessionIdFromCookie() on the wrapped request object. isRequestedSessionIdFromUrl() - Method in interface javax.servlet.http.HttpServletRequest Deprecated. As of Version 2.1 of the Java Servlet API, use HttpServletRequest.isRequestedSessionIdFromURL() instead. isRequestedSessionIdFromUrl() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return isRequestedSessionIdFromUrl() on the wrapped request object. isRequestedSessionIdFromURL() - Method in interface javax.servlet.http.HttpServletRequest Checks whether the requested session ID came in as part of the request URL. isRequestedSessionIdFromURL() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return isRequestedSessionIdFromURL() on the wrapped request object. isRequestedSessionIdValid() - Method in interface javax.servlet.http.HttpServletRequest Checks whether the requested session ID is still valid. isRequestedSessionIdValid() - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return isRequestedSessionIdValid() on the wrapped request object. isSecure() - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to return isSecure() on the wrapped request object. isSecure() - Method in interface javax.servlet.ServletRequest Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. isUserInRole(String) - Method in interface javax.servlet.http.HttpServletRequest Returns a boolean indicating whether the authenticated user is included in the specified logical "role". isUserInRole(String) - Method in class javax.servlet.http.HttpServletRequestWrapper The default behavior of this method is to return isUserInRole(String role) on the wrapped request object. -------------------------------------------------------------------------------- J javax.servlet - package javax.servlet This chapter describes the javax.servlet package. javax.servlet.http - package javax.servlet.http This chapter describes the javax.servlet.http package. -------------------------------------------------------------------------------- L log(Exception, String) - Method in interface javax.servlet.ServletContext Deprecated. As of Java Servlet API 2.1, use ServletContext.log(String message, Throwable throwable) instead. This method was originally defined to write an exception's stack trace and an explanatory error message to the servlet log file. log(String) - Method in interface javax.servlet.ServletContext Writes the specified message to a servlet log file, usually an event log. log(String) - Method in class javax.servlet.GenericServlet Writes the specified message to a servlet log file, prepended by the servlet's name. log(String, Throwable) - Method in interface javax.servlet.ServletContext Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file. log(String, Throwable) - Method in class javax.servlet.GenericServlet Writes an explanatory message and a stack trace for a given Throwable exception to the servlet log file, prepended by the servlet's name. -------------------------------------------------------------------------------- P parsePostData(int, ServletInputStream) - Static method in class javax.servlet.http.HttpUtils Deprecated. Parses data from an HTML form that the client sends to the server using the HTTP POST method and the application/x-www-form-urlencoded MIME type. parseQueryString(String) - Static method in class javax.servlet.http.HttpUtils Deprecated. Parses a query string passed from the client to the server and builds a HashTable object with key-value pairs. print(boolean) - Method in class javax.servlet.ServletOutputStream Writes a boolean value to the client, with no carriage return-line feed (CRLF) character at the end. print(char) - Method in class javax.servlet.ServletOutputStream Writes a character to the client, with no carriage return-line feed (CRLF) at the end. print(double) - Method in class javax.servlet.ServletOutputStream Writes a double value to the client, with no carriage return-line feed (CRLF) at the end. print(float) - Method in class javax.servlet.ServletOutputStream Writes a float value to the client, with no carriage return-line feed (CRLF) at the end. print(int) - Method in class javax.servlet.ServletOutputStream Writes an int to the client, with no carriage return-line feed (CRLF) at the end. print(long) - Method in class javax.servlet.ServletOutputStream Writes a long value to the client, with no carriage return-line feed (CRLF) at the end. print(String) - Method in class javax.servlet.ServletOutputStream Writes a String to the client, without a carriage return-line feed (CRLF) character at the end. println() - Method in class javax.servlet.ServletOutputStream Writes a carriage return-line feed (CRLF) to the client. println(boolean) - Method in class javax.servlet.ServletOutputStream Writes a boolean value to the client, followed by a carriage return-line feed (CRLF). println(char) - Method in class javax.servlet.ServletOutputStream Writes a character to the client, followed by a carriage return-line feed (CRLF). println(double) - Method in class javax.servlet.ServletOutputStream Writes a double value to the client, followed by a carriage return-line feed (CRLF). println(float) - Method in class javax.servlet.ServletOutputStream Writes a float value to the client, followed by a carriage return-line feed (CRLF). println(int) - Method in class javax.servlet.ServletOutputStream Writes an int to the client, followed by a carriage return-line feed (CRLF) character. println(long) - Method in class javax.servlet.ServletOutputStream Writes a long value to the client, followed by a carriage return-line feed (CRLF). println(String) - Method in class javax.servlet.ServletOutputStream Writes a String to the client, followed by a carriage return-line feed (CRLF). putValue(String, Object) - Method in interface javax.servlet.http.HttpSession Deprecated. As of Version 2.2, this method is replaced by HttpSession.setAttribute(java.lang.String, java.lang.Object) -------------------------------------------------------------------------------- R readLine(byte[], int, int) - Method in class javax.servlet.ServletInputStream Reads the input stream, one line at a time. removeAttribute(String) - Method in interface javax.servlet.ServletContext Removes the attribute with the given name from the servlet context. removeAttribute(String) - Method in class javax.servlet.ServletRequestWrapper The default behavior of this method is to call removeAttribute(String name) on the wrapped request object. removeAttribute(String) - Method in interface javax.servlet.ServletRequest Removes an attribute from this request. removeAttribute(String) - Method in interface javax.servlet.http.HttpSession Removes the object bound with the specified name from this session. removeValue(String) - Method in interface javax.servlet.http.HttpSession Deprecated. As of Version 2.2, this method is replaced by HttpSession.removeAttribute(java.lang.String) requestDestroyed(ServletRequestEvent) - Method in interface javax.servlet.ServletRequestListener The request is about to go out of scope of the web application. RequestDispatcher - interface javax.servlet.RequestDispatcher. Defines an object that receives requests from the client and sends them to any resource (such as a servlet, HTML file, or JSP file) on the server. requestInitialized(ServletRequestEvent) - Method in interface javax.servlet.ServletRequestListener The request is about to come into scope of the web application. reset() - Method in interface javax.servlet.ServletResponse Clears any data that exists in the buffer as well as the status code and headers. reset() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to call reset() on the wrapped response object. resetBuffer() - Method in interface javax.servlet.ServletResponse Clears the content of the underlying buffer in the response without clearing headers or status code. resetBuffer() - Method in class javax.servlet.ServletResponseWrapper The default behavior of this method is to call resetBuffer() on the wrapped response object. -------------------------------------------------------------------------------- S SC_ACCEPTED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (202) indicating that a request was accepted for processing, but was not completed. SC_BAD_GATEWAY - Static variable in interface javax.servlet.http.HttpServletResponse Status code (502) indicating that the HTTP server received an invalid response from a server it consulted when acting as a proxy or gateway. SC_BAD_REQUEST - Static variable in interface javax.servlet.http.HttpServletResponse Status code (400) indicating the request sent by the client was syntactically incorrect. SC_CONFLICT - Static variable in interface javax.servlet.http.HttpServletResponse Status code (409) indicating that the request could not be completed due to a conflict with the current state of the resource. SC_CONTINUE - Static variable in interface javax.servlet.http.HttpServletResponse Status code (100) indicating the client can continue. SC_CREATED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (201) indicating the request succeeded and created a new resource on the server. SC_EXPECTATION_FAILED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (417) indicating that the server could not meet the expectation given in the Expect request header. SC_FORBIDDEN - Static variable in interface javax.servlet.http.HttpServletResponse Status code (403) indicating the server understood the request but refused to fulfill it. SC_FOUND - Static variable in interface javax.servlet.http.HttpServletResponse Status code (302) indicating that the resource reside temporarily under a different URI. SC_GATEWAY_TIMEOUT - Static variable in interface javax.servlet.http.HttpServletResponse Status code (504) indicating that the server did not receive a timely response from the upstream server while acting as a gateway or proxy. SC_GONE - Static variable in interface javax.servlet.http.HttpServletResponse Status code (410) indicating that the resource is no longer available at the server and no forwarding address is known. SC_HTTP_VERSION_NOT_SUPPORTED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (505) indicating that the server does not support or refuses to support the HTTP protocol version that was used in the request message. SC_INTERNAL_SERVER_ERROR - Static variable in interface javax.servlet.http.HttpServletResponse Status code (500) indicating an error inside the HTTP server which prevented it from fulfilling the request. SC_LENGTH_REQUIRED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (411) indicating that the request cannot be handled without a defined Content-Length. SC_METHOD_NOT_ALLOWED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (405) indicating that the method specified in the Request-Line is not allowed for the resource identified by the Request-URI. SC_MOVED_PERMANENTLY - Static variable in interface javax.servlet.http.HttpServletResponse Status code (301) indicating that the resource has permanently moved to a new location, and that future references should use a new URI with their requests. SC_MOVED_TEMPORARILY - Static variable in interface javax.servlet.http.HttpServletResponse Status code (302) indicating that the resource has temporarily moved to another location, but that future references should still use the original URI to access the resource. SC_MULTIPLE_CHOICES - Static variable in interface javax.servlet.http.HttpServletResponse Status code (300) indicating that the requested resource corresponds to any one of a set of representations, each with its own specific location. SC_NO_CONTENT - Static variable in interface javax.servlet.http.HttpServletResponse Status code (204) indicating that the request succeeded but that there was no new information to return. SC_NON_AUTHORITATIVE_INFORMATION - Static variable in interface javax.servlet.http.HttpServletResponse Status code (203) indicating that the meta information presented by the client did not originate from the server. SC_NOT_ACCEPTABLE - Static variable in interface javax.servlet.http.HttpServletResponse Status code (406) indicating that the resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request. SC_NOT_FOUND - Static variable in interface javax.servlet.http.HttpServletResponse Status code (404) indicating that the requested resource is not available. SC_NOT_IMPLEMENTED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (501) indicating the HTTP server does not support the functionality needed to fulfill the request. SC_NOT_MODIFIED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (304) indicating that a conditional GET operation found that the resource was available and not modified. SC_OK - Static variable in interface javax.servlet.http.HttpServletResponse Status code (200) indicating the request succeeded normally. SC_PARTIAL_CONTENT - Static variable in interface javax.servlet.http.HttpServletResponse Status code (206) indicating that the server has fulfilled the partial GET request for the resource. SC_PAYMENT_REQUIRED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (402) reserved for future use. SC_PRECONDITION_FAILED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (412) indicating that the precondition given in one or more of the request-header fields evaluated to false when it was tested on the server. SC_PROXY_AUTHENTICATION_REQUIRED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (407) indicating that the client MUST first authenticate itself with the proxy. SC_REQUEST_ENTITY_TOO_LARGE - Static variable in interface javax.servlet.http.HttpServletResponse Status code (413) indicating that the server is refusing to process the request because the request entity is larger than the server is willing or able to process. SC_REQUEST_TIMEOUT - Static variable in interface javax.servlet.http.HttpServletResponse Status code (408) indicating that the client did not produce a request within the time that the server was prepared to wait. SC_REQUEST_URI_TOO_LONG - Static variable in interface javax.servlet.http.HttpServletResponse Status code (414) indicating that the server is refusing to service the request because the Request-URI is longer than the server is willing to interpret. SC_REQUESTED_RANGE_NOT_SATISFIABLE - Static variable in interface javax.servlet.http.HttpServletResponse Status code (416) indicating that the server cannot serve the requested byte range. SC_RESET_CONTENT - Static variable in interface javax.servlet.http.HttpServletResponse Status code (205) indicating that the agent SHOULD reset the document view which caused the request to be sent. SC_SEE_OTHER - Static variable in interface javax.servlet.http.HttpServletResponse Status code (303) indicating that the response to the request can be found under a different URI. SC_SERVICE_UNAVAILABLE - Static variable in interface javax.servlet.http.HttpServletResponse Status code (503) indicating that the HTTP server is temporarily overloaded, and unable to handle the request. SC_SWITCHING_PROTOCOLS - Static variable in interface javax.servlet.http.HttpServletResponse Status code (101) indicating the server is switching protocols according to Upgrade header. SC_TEMPORARY_REDIRECT - Static variable in interface javax.servlet.http.HttpServletResponse Status code (307) indicating that the requested resource resides temporarily under a different URI. SC_UNAUTHORIZED - Static variable in interface javax.servlet.http.HttpServletResponse Status code (401) indicating that the request requires HTTP authentication. SC_UNSUPPORTED_MEDIA_TYPE - Static variable in interface javax.servlet.http.HttpServletResponse Status code (415) indicating that the server is refusing to service the request because the entity of the request is in a format not supported by the requested resource for the requested method. SC_USE_PROXY - Static variable in interface javax.servlet.http.HttpServletResponse Status code (305) indicating that the requested resource MUST be accessed through the proxy given by the Location field. sendError(int) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to call sendError(int sc) on the wrapped response object. sendError(int) - Method in interface javax.servlet.http.HttpServletResponse Sends an error response to the client using the specified status code and clearing the buffer. sendError(int, String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to call sendError(int sc, String msg) on the wrapped response object. sendError(int, String) - Method in interface javax.servlet.http.HttpServletResponse Sends an error response to the client using the specified status. sendRedirect(String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of this method is to return sendRedirect(String location) on the wrapped response object. sendRedirect(String) - Method in interface javax.servlet.http.HttpServletResponse Sends a temporary redirect response to the client using the specified redirect location URL. service(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Receives standard HTTP requests from the public service method and dispatches them to the doXXX methods defined in this class. service(ServletRequest, ServletResponse) - Method in interfac
Java Servlet API说明文档 绪言 这是一份关于2.1版JavaServletAPI的说明文档,作为对这本文档的补充,你可以到http://java.sun.com/products/servlet/index.html下面下载Javadoc格式的文档。 谁需要读这份文档 这份文档描述了JavaServletAPI的最新版本2.1版。所以,这本书对于Servlet的开发者及servlet引擎的开发者同样适用。 JavaServletAPI的组成 JavaServletAPI由两个软件包组成:一个是对应HTTP的软件包,另一个是不对应HTTP的通用的软件包。这两个软件包的同时存在使得JavaServletAPI能够适应将来的其他请求-响应的协议。 这份文档以及刚才提及的Javadoc格式的文档都描述了这两个软件包,Javadoc格式的文档还描述了你应该如何使用这两个软件包中的所有方法。 有关规范 你也许对下面的这些Internet规范感兴趣,这些规范将直接影响到ServletAPI的发展和执行。你可以从http://info.internet.isi.edu/7c/in-notes/rfc/.cache找到下面提到的所有这些RFC规范。 RFC1738统一资源定位器(URL) RFC1808相关统一资源定位器 RFC1945超文本传输协议--HTTP/1.0 RFC2045多用途Internet邮件扩展(多用途网际邮件扩充协议(MIME))第一部分:Internet信息体格式 RFC2046多用途Internet邮件扩展(多用途网际邮件扩充协议(MIME))第二部分:媒体类型 RFC2047多用途网际邮件扩充协议(MIME)(多用途Internet邮件扩展)第三部分:信息标题扩展用于非ASCII文本 RFC2048多用途Internet邮件扩展(多用途网际邮件扩充协议(MIME))第四部分:注册步骤 RFC2049多用途Internet邮件扩展(多用途网际邮件扩充协议(MIME))第五部分:一致性标准和例子 RFC2068超文本传输协议--HTTP/1.1 RFC2069一个扩展HTTP:摘要访问鉴定 RFC2109HTTP状态管理机制 RFC2145HTTP版本号的使用和解释 RFC2324超文本CoffeePot控制协议(HTCPCP/1.0) 万维网协会(http://www.w3.org)管理着这些协议的规范和执行。 有关JavaServlets JavaTMservlets是一个不受平台约束的Java小程序,它可以被用来通过多种方法扩充一个Web服务器的功能。你可以把Servlet理解成Server上的applets,它被编译成字节码,这样它就可以被动态地载入并用效地扩展主机的处理能力。 Servlet与applets不同的地方是,它不运行在Web浏览器或其他图形化的用户界面上。Servlet通过servlet引擎运行在Web服务器中,以执行请求和响应,请求、响应的典型范例是HTTP协议。 一个客户端程序,可以是一个Web浏览器,或者是非其他的可以连接上Internet的程序,它会访问Web服务器并发出请求。这个请求被运行在Web服务器上的Servlet引擎处理,并返回响应到Servlet。Servlet通过HTTP将这个响应转发到客户端。 在功能上,Servlet与CGI、NSAPI有点类似,但是,与他们不同的是:Servlet具有平台无关性。 JavaServlet概论 Servlet与其他普通的server扩展机制有以下进步: 因为它采用了不同的进程处理模式,所以它比CGI更快。 它使用了许多Web服务器都支持的标准的API。 它继承了Java的所有优势,包括易升级以及平台无关性。 它可以调用Java所提供的大量的API的功能模块。 这份文档说明了JavaServletAPI的类和接口的方法。有关更多的信息,请参看下面的API说明。 Servlet的生命周期 一个Javaservlet具有一个生命周期,这个生命周期定义了一个Servlet如何被载入并被初始化,如何接收请求并作出对请求的响应,如何被从服务中清除。Servlet的生命周期被javax.servlet.Servlet这个接口所定义。 所有的JavaServlet都会直接地或间接地执行javax.servlet.Servlet接口,这样它才能在一个Servlet引擎中运行。Servlet引擎是Web服务器按照JavaServletAPI定制的扩展。Servlet引擎提供网络服务,能够理解MIME请求,并提供一个运行Servlet的容器。 javax.servlet.Servlet接口定义了在Servlet的生命周期中特定时间以及特定顺序被调用的方法。 Servlet的解析和载入 Servlet引擎解析并载入一个Servlet,这个过程可以发生在引擎启动时,需要一个Servlet去响应请求时,以及在此之间的任何时候。 Servlet引擎利用Java类载入工具载入一个Servlet,Servlet引擎可以从一个本地的文件系统、一个远程的文件系统以及网络载入Servlet。 Servlet的初始化 Servlet引擎载入Servlet后,Servlet引擎必须对Servlet进行初始化,在这一过程中,你可以读取一些固定存储的数据、初始化JDBC的连接以及建立与其他资源的连接。 在初始化过程中,javax.servlet.Servlet接口的init()方法提供了Servlet的初始化信息。这样,Servlet可以对自己进行配置。 init()方法获得了一个Servlet配置对象(ServletConfig)。这个对象在Servlet引擎中执行,并允许Servlet通过它获处相关参数。这个对象使得Servlet能够访问ServletContext对象。 Servlet处理请求\r Servlet被初始化之后,它已经可以处理来自客户端的请求,每一个来自客户端的请求都被描述成一个ServletRequest对象,Servlet的响应被描述成一个ServletResponse对象。 当客户端发出请求时,Servlet引擎传递给Servlet一个ServletRequest对象和一个ServletResponse对象,这两个对象作为参数传递到service()方法中。 Servlet也可以执行ServletRequest接口和ServletResponse接口。ServletRequest接口使得Servlet有权使用客户端发出的请求。Servlet可以通过ServletInputStream对象读取请求信息。 ServletResponse接口允许Servlet建立响应头和状态代码。通过执行这个接口,Servlet有权使用ServletOutputStream类来向客户端返回数据。 多线程和映射\r 在多线程的环境下,Servlet必须能处理许多同时发生的请求。例外的情况是这个Servlet执行了SingleThreadModel接口,如果是那样的话,Servlet只能同时处理一个请求。 Servlet依照Servlet引擎的映射来响应客户端的请求。一个映射对包括一个Servlet实例以及一个Servlet返回数据的URL,例如:HelloServletwith/hello/index.html。 然而,一个映射可能是由一个URL和许多Servlet实例组成,例如:一个分布式的Servlet引擎可能运行在不止一个的服务器中,这样的话,每一个服务器中都可能有一个Servlet实例,以平衡进程的载入。作为一个Servlet的开发者,你不能假定一个Servlet只有一个实例。 Servlet的卸载 Servlet引擎并不必需保证一个Servlet在任何时候或在服务开启的任何时候都被载入。Servlet引擎可以自由的在任何时候使用或清除一个Servlet。因此,我们不能依赖一个类或实例来存储重要的信息。 当Servlet引擎决定卸载一个Servlet时(例如,如果这个引擎被关闭或者需要让资源),这个引擎必须允许Servlet释放正在使用的资源并存储有关资料。为了完成以上工作,引擎会调用Servlet的destroy()方法。 在卸载一个Servlet之前,Servlet引擎必须等待所有的service()方法完成或超时结束(Servlet引擎会对超时作出定义)。当一个Servlet被卸载时,引擎将不能给Servlet发送任何请求。引擎必须释放Servlet并完成无用存储单元的收集 Servlet映射技术\r 作为一个Servlet引擎的开发者,你必须对于如何映射客户端的请求到Servlet有大量的适应性。这份说明文档不规定映射如何发生。但是,你必须能够自由地运用下面的所有技术: 映射一个Servlet到一个URL 例如,你可以指定一个特殊的Servlet它仅被来自/feedback/index.html的请求调用。 映射一个Servlet到以一个指定的目录名开始的所有URL 例如,你可以映射一个Servlet到/catalog,这样来自/catalog/、/catalog/garden和/catalog/housewares/index.html的请求都会被映射到这个Servlet。但是来自/catalogtwo或/catalog.html的请求没被映射。 映射一个Servlet到所有以一个特定的字段结尾的所有URL 例如,你可以映射一个来自于所有以in.thtml结尾的请求到一个特定的Servlet。 映射一个Servlet到一个特殊的URL/servlet/servlet_name。 例如,如果你建立了一个名叫listattributes的Servlet,你可以通过使用/servlet/listattributes来访问这个Servlet。 通过类名调用Servlet 例如,如果Servlet引擎接收了来自/servlet/com.foo.servlet.MailServlet的请求,Servlet引擎会载入这个com.foo.servlet.MailServlet类,建立实例,并通过这个Servlet来处理请求。 Servlet环境 ServletContext接口定义了一个Servlet环境对象,这个对象定义了一个在Servlet引擎上的Servlet的视图。通过使用这个对象,Servlet可以记录事件、得到资源并得到来自Servlet引擎的类(例如RequestDispatcher对象)。一个Servlet只能运行在一个Servlet环境中,但是不同的Servlet可以在Servlet引擎上有不同的视图。 如果Servlet引擎支持虚拟主机,每个虚拟主机有一个Servlet环境。一个Servlet环境不能在虚拟主机之间共享。 Servlet引擎能够允许一个Servlet环境有它自己的活动范围。 例如,一个Servlet环境是属于bank应用的,它将被映射到/bank目录下。在这种情况下,一个对getContext方法的调用会返回/bank的Servlet环境。 HTTP会话 HTTP是一个没有状态的协议。要建立一个有效的Web服务应用,你必须能够识别一个连续的来自远端的客户机的唯一的请求。随着时间的过去,发展了许多会话跟踪的技术,但是使用起来都比较麻烦。 JavaServletAPI提供了一个简单的接口,通过这个接口,Servlet引擎可以有效地跟踪用户的会话。 建立Session 因为HTTP是一个请求-响应协议,一个会话在客户机加入之前会被认为是一个新的会话。加入的意思是返回会话跟踪信息到服务器中,指出会话已被建立。在客户端加入之前,我们不能判断下一个客户端请求是目前会话的一部分。 在下面的情况下,Session会被认为是新的Session。 客户端的Session在此之前还不知道 客户端选择不加入Session,例如,如果客户端拒绝接收来自服务器的cookie 作为一个Servlet的开发者,你必须决定你的Web应用是否处理客户机不加入或不能加入Session。服务器会在Web服务器或Servlet规定的时间内维持一个Session对象。当Session终止时,服务器会释放Session对象以及所有绑定在Session上的对象。 绑定对象到Session中 如果有助于你处理应用的数据需求,你也许需要绑定对象到Session中,你可以通过一个唯一的名字绑定任何的对象到Session中,这时,你需要使用HttpSession对象。任何绑定到Session上的对象都可以被处理同一会话的Servlet调用。 有些对象可能需要你知道什么时候会被放置到Session中或从Session中移开。你可以通过使用HttpSessionBindingListener接口获得这些信息。当你的应用存储数据到Session中,或从Session中清除数据,Servlet都会通过HttpSessionBindingListener检杳什么类被绑定或被取消绑定。这个接口的方法会通报被绑定或被取消绑定的对象。 绪言 这是一份关于2.1版JavaServletAPI的说明文档,作为对这本文档的补充,你可以到http://java.sun.com/products/servlet/index.html下面下载Javadoc格式的文档。 谁需要读这份文档 这份文档描述了JavaServletAPI的最新版本2.1版。所以,这本书对于Servlet的开发者及servlet引擎的开发者同样适用。 JavaServletAPI的组成 JavaServletAPI由两个软件包组成:一个是对应HTTP的软件包,另一个是不对应HTTP的通用的软件包。这两个软件包的同时存在使得JavaServletAPI能够适应将来的其他请求-响应的协议。 这份文档以及刚才提及的Javadoc格式的文档都描述了这两个软件包,Javadoc格式的文档还描述了你应该如何使用这两个软件包中的所有方法。 有关规范 你也许对下面的这些Internet规范感兴趣,这些规范将直接影响到ServletAPI的发展和执行。你可以从http://info.internet.isi.edu/7c/in-notes/rfc/.cache找到下面提到的所有这些RFC规范。 RFC1738统一资源定位器(URL) RFC1808相关统一资源定位器 RFC1945超文本传输协议--HTTP/1.0 RFC2045多用途Internet邮件扩展(多用途网际邮件扩充协议(MIME))第一部分:Internet信息体格式 RFC2046多用途Internet邮件扩展(多用途网际邮件扩充协议(MIME))第二部分:媒体类型 RFC2047多用途网际邮件扩充协议(MIME)(多用途Internet邮件扩展)第三部分:信息标题扩展用于非ASCII文本 RFC2048多用途Internet邮件扩展(多用途网际邮件扩充协议(MIME))第四部分:注册步骤 RFC2049多用途Internet邮件扩展(多用途网际邮件扩充协议(MIME))第五部分:一致性标准和例子 RFC2068超文本传输协议--HTTP/1.1 RFC2069一个扩展HTTP:摘要访问鉴定 RFC2109HTTP状态管理机制 RFC2145HTTP版本号的使用和解释 RFC2324超文本CoffeePot控制协议(HTCPCP/1.0) 万维网协会(http://www.w3.org)管理着这些协议的规范和执行。 有关JavaServlets JavaTMservlets是一个不受平台约束的Java小程序,它可以被用来通过多种方法扩充一个Web服务器的功能。你可以把Servlet理解成Server上的applets,它被编译成字节码,这样它就可以被动态地载入并用效地扩展主机的处理能力。 Servlet与applets不同的地方是,它不运行在Web浏览器或其他图形化的用户界面上。Servlet通过servlet引擎运行在Web服务器中,以执行请求和响应,请求、响应的典型范例是HTTP协议。 一个客户端程序,可以是一个Web浏览器,或者是非其他的可以连接上Internet的程序,它会访问Web服务器并发出请求。这个请求被运行在Web服务器上的Servlet引擎处理,并返回响应到Servlet。Servlet通过HTTP将这个响应转发到客户端。 在功能上,Servlet与CGI、NSAPI有点类似,但是,与他们不同的是:Servlet具有平台无关性。 JavaServlet概论 Servlet与其他普通的server扩展机制有以下进步: 因为它采用了不同的进程处理模式,所以它比CGI更快。 它使用了许多Web服务器都支持的标准的API。 它继承了Java的所有优势,包括易升级以及平台无关性。 它可以调用Java所提供的大量的API的功能模块。 这份文档说明了JavaServletAPI的类和接口的方法。有关更多的信息,请参看下面的API说明。 Servlet的生命周期 一个Javaservlet具有一个生命周期,这个生命周期定义了一个Servlet如何被载入并被初始化,如何接收请求并作出对请求的响应,如何被从服务中清除。Servlet的生命周期被javax.servlet.Servlet这个接口所定义。 所有的JavaServlet都会直接地或间接地执行javax.servlet.Servlet接口,这样它才能在一个Servlet引擎中运行。Servlet引擎是Web服务器按照JavaServletAPI定制的扩展。Servlet引擎提供网络服务,能够理解MIME请求,并提供一个运行Servlet的容器。 javax.servlet.Servlet接口定义了在Servlet的生命周期中特定时间以及特定顺序被调用的方法。 Servlet的解析和载入\r Servlet引擎解析并载入一个Servlet,这个过程可以发生在引擎启动时,需要一个Servlet去响应请求时,以及在此之间的任何时候。 Servlet引擎利用Java类载入工具载入一个Servlet,Servlet引擎可以从一个本地的文件系统、一个远程的文件系统以及网络载入Servlet。 Servlet的初始化 Servlet引擎载入Servlet后,Servlet引擎必须对Servlet进行初始化,在这一过程中,你可以读取一些固定存储的数据、初始化JDBC的连接以及建立与其他资源的连接。 在初始化过程中,javax.servlet.Servlet接口的init()方法提供了Servlet的初始化信息。这样,Servlet可以对自己进行配置。 init()方法获得了一个Servlet配置对象(ServletConfig)。这个对象在Servlet引擎中执行,并允许Servlet通过它获处相关参数。这个对象使得Servlet能够访问ServletContext对象。 Servlet处理请求\r Servlet被初始化之后,它已经可以处理来自客户端的请求,每一个来自客户端的请求都被描述成一个ServletRequest对象,Servlet的响应被描述成一个ServletResponse对象。 当客户端发出请求时,Servlet引擎传递给Servlet一个ServletRequest对象和一个ServletResponse对象,这两个对象作为参数传递到service()方法中。 Servlet也可以执行ServletRequest接口和ServletResponse接口。ServletRequest接口使得Servlet有权使用客户端发出的请求。Servlet可以通过ServletInputStream对象读取请求信息。 ServletResponse接口允许Servlet建立响应头和状态代码。通过执行这个接口,Servlet有权使用ServletOutputStream类来向客户端返回数据。 多线程和映射\r 在多线程的环境下,Servlet必须能处理许多同时发生的请求。例外的情况是这个Servlet执行了SingleThreadModel接口,如果是那样的话,Servlet只能同时处理一个请求。 Servlet依照Servlet引擎的映射来响应客户端的请求。一个映射对包括一个Servlet实例以及一个Servlet返回数据的URL,例如:HelloServletwith/hello/index.html。 然而,一个映射可能是由一个URL和许多Servlet实例组成,例如:一个分布式的Servlet引擎可能运行在不止一个的服务器中,这样的话,每一个服务器中都可能有一个Servlet实例,以平衡进程的载入。作为一个Servlet的开发者,你不能假定一个Servlet只有一个实例。 Servlet的卸载 Servlet引擎并不必需保证一个Servlet在任何时候或在服务开启的任何时候都被载入。Servlet引擎可以自由的在任何时候使用或清除一个Servlet。因此,我们不能依赖一个类或实例来存储重要的信息。 当Servlet引擎决定卸载一个Servlet时(例如,如果这个引擎被关闭或者需要让资源),这个引擎必须允许Servlet释放正在使用的资源并存储有关资料。为了完成以上工作,引擎会调用Servlet的destroy()方法。 在卸载一个Servlet之前,Servlet引擎必须等待所有的service()方法完成或超时结束(Servlet引擎会对超时作出定义)。当一个Servlet被卸载时,引擎将不能给Servlet发送任何请求。引擎必须释放Servlet并完成无用存储单元的收集 Servlet映射技术\r 作为一个Servlet引擎的开发者,你必须对于如何映射客户端的请求到Servlet有大量的适应性。这份说明文档不规定映射如何发生。但是,你必须能够自由地运用下面的所有技术: 映射一个Servlet到一个URL 例如,你可以指定一个特殊的Servlet它仅被来自/feedback/index.html的请求调用。 映射一个Servlet到以一个指定的目录名开始的所有URL 例如,你可以映射一个Servlet到/catalog,这样来自/catalog/、/catalog/garden和/catalog/housewares/index.html的请求都会被映射到这个Servlet。但是来自/catalogtwo或/catalog.html的请求没被映射。 映射一个Servlet到所有以一个特定的字段结尾的所有URL 例如,你可以映射一个来自于所有以in.thtml结尾的请求到一个特定的Servlet。 映射一个Servlet到一个特殊的URL/servlet/servlet_name。 例如,如果你建立了一个名叫listattributes的Servlet,你可以通过使用/servlet/listattributes来访问这个Servlet。 通过类名调用Servlet 例如,如果Servlet引擎接收了来自/servlet/com.foo.servlet.MailServlet的请求,Servlet引擎会载入这个com.foo.servlet.MailServlet类,建立实例,并通过这个Servlet来处理请求。 Servlet环境 ServletContext接口定义了一个Servlet环境对象,这个对象定义了一个在Servlet引擎上的Servlet的视图。通过使用这个对象,Servlet可以记录事件、得到资源并得到来自Servlet引擎的类(例如RequestDispatcher对象)。一个Servlet只能运行在一个Servlet环境中,但是不同的Servlet可以在Servlet引擎上有不同的视图。 如果Servlet引擎支持虚拟主机,每个虚拟主机有一个Servlet环境。一个Servlet环境不能在虚拟主机之间共享。 Servlet引擎能够允许一个Servlet环境有它自己的活动范围。 例如,一个Servlet环境是属于bank应用的,它将被映射到/bank目录下。在这种情况下,一个对getContext方法的调用会返回/bank的Servlet环境。 HTTP会话 HTTP是一个没有状态的协议。要建立一个有效的Web服务应用,你必须能够识别一个连续的来自远端的客户机的唯一的请求。随着时间的过去,发展了许多会话跟踪的技术,但是使用起来都比较麻烦。 JavaServletAPI提供了一个简单的接口,通过这个接口,Servlet引擎可以有效地跟踪用户的会话。 建立Session 因为HTTP是一个请求-响应协议,一个会话在客户机加入之前会被认为是一个新的会话。加入的意思是返回会话跟踪信息到服务器中,指出会话已被建立。在客户端加入之前,我们不能判断下一个客户端请求是目前会话的一部分。 在下面的情况下,Session会被认为是新的Session。 客户端的Session在此之前还不知道 客户端选择不加入Session,例如,如果客户端拒绝接收来自服务器的cookie 作为一个Servlet的开发者,你必须决定你的Web应用是否处理客户机不加入或不能加入Session。服务器会在Web服务器或Servlet规定的时间内维持一个Session对象。当Session终止时,服务器会释放Session对象以及所有绑定在Session上的对象。 绑定对象到Session中 如果有助于你处理应用的数据需求,你也许需要绑定对象到Session中,你可以通过一个唯一的名字绑定任何的对象到Session中,这时,你需要使用HttpSession对象。任何绑定到Session上的对象都可以被处理同一会话的Servlet调用。 有些对象可能需要你知道什么时候会被放置到Session中或从Session中移开。你可以通过使用HttpSessionBindingListener接口获得这些信息。当你的应用存储数据到Session中,或从Session中清除数据,Servlet都会通过HttpSessionBindingListener检杳什么类被绑定或被取消绑定。这个接口的方法会通报被绑定或被取消绑定的对象。 软件包:javax.servlet.http 所包含的接口:HttpServletRequest;HttpServletResponse;HttpSession;HttpSessionBindingListener;HttpSessionContext。 所包含的类:Cookie;HttpServlet;HttpSessionBindingEvent;HttpUtils。 一、HttpServletRequest接口 定义\ publicinterfaceHttpServletRequestextendsServletRequest; 用来处理一个对Servlet的HTTP格式的请求信息。 方法 1、getAuthType publicStringgetAuthType(); 返回这个请求的身份验证模式。 2、getCookies publicCookie[]getCookies(); 返回一个数组,该数组包含这个请求中当前的所有cookie。如果这个请求中没有cookie,返回一个空数组。 3、getDateHeader publiclonggetDateHeader(Stringname); 返回指定的请求头域的值,这个值被转换成一个反映自1970-1-1日(GMT)以来的精确到毫秒的长整数。 如果头域不能转换,抛出一个IllegalArgumentException。如果这个请求头域不存在,这个方法返回-1。 4、getHeader publicStringgetHeader(Stringname); 返回一个请求头域的值。(译者注:与上一个方法不同的是,该方法返回一个字符串) 如果这个请求头域不存在,这个方法返回-1。 5、getHeaderNames publicEnumerationgetHeaderNames(); 该方法返回一个String对象的列表,该列表反映请求的所有头域名。 有的引擎可能不允许通过这种方法访问头域,在这种情况下,这个方法返回一个空的列表。 6、getIntHeader publicintgetIntHeader(Stringname); 返回指定的请求头域的值,这个值被转换成一个整数。 如果头域不能转换,抛出一个IllegalArgumentException。如果这个请求头域不存在,这个方法返回-1。 7、getMethod publicStringgetMethod(); 返回这个请求使用的HTTP方法(例如:GET、POST、PUT) 8、getPathInfo publicStringgetPathInfo(); 这个方法返回在这个请求的URL的Servlet路径之后的请求URL的额外的路径信息。如果这个请求URL包括一个查询字符串,在返回值内将不包括这个查询字符串。这个路径在返回之前必须经过URL解码。如果在这个请求的URL的Servlet路径之后没有路径信息。这个方法返回空值。 9、getPathTranslated publicStringgetPathTranslated(); 这个方法获得这个请求的URL的Servlet路径之后的额外的路径信息,并将它转换成一个真实的路径。在进行转换前,这个请求的URL必须经过URL解码。如果在这个URL的Servlet路径之后没有附加路径信息。这个方法返回空值。 10、getQueryString publicStringgetQueryString(); 返回这个请求URL所包含的查询字符串。一个查询字串符在一个URL中由一个“?”引出。如果没有查询字符串,这个方法返回空值。 11、getRemoteUser publicStringgetRemoteUser 返回作了请求的用户名,这个信息用来作HTTP用户论证。 如果在请求中没有用户名信息,这个方法返回空值。 12、getRequestedSessionId publicStringgetRequestedSessionId(); 返回这个请求相应的sessionid。如果由于某种原因客户端提供的sessionid是无效的,这个sessionid将与在当前session中的sessionid不同,与此同时,将建立一个新的session。 如果这个请求没与一个session关联,这个方法返回空值。 13、getRequestURI publicStringgetRequestURI(); 从HTTP请求的第一行返回请求的URL中定义被请求的资源的部分。如果有一个查询字符串存在,这个查询字符串将不包括在返回值当中。例如,一个请求通过/catalog/books?id=1这样的URL路径访问,这个方法将返回/catalog/books。这个方法的返回值包括了Servlet路径和路径信息。 如果这个URL路径中的的一部分经过了URL编码,这个方法的返回值在返回之前必须经过解码。 14、getServletPath publicStringgetServletPath(); 这个方法返回请求URL反映调用Servlet的部分。例如,一个Servlet被映射到/catalog/summer这个URL路径,而一个请求使用了/catalog/summer/casual这样的路径。所谓的反映调用Servlet的部分就是指/catalog/summer。 如果这个Servlet不是通过路径匹配来调用。这个方法将返回一个空值。 15、getSession publicHttpSessiongetSession(); publicHttpSessiongetSession(booleancreate); 返回与这个请求关联的当前的有效的session。如果调用这个方法时没带参数,那么在没有session与这个请求关联的情况下,将会新建一个session。如果调用这个方法时带入了一个布尔型的参数,只有当这个参数为真时,session才会被建立。 为了确保session能够被完全维持。Servlet开发者必须在响应被提交之前调用该方法。 如果带入的参数为假,而且没有session与这个请求关联。这个方法会返回空值。 16、isRequestedSessionIdValid publicbooleanisRequestedSessionIdValid(); 这个方法检查与此请求关联的session当前是不是有效。如果当前请求中使用的session无效,它将不能通过getSession方法返回。 17、isRequestedSessionIdFromCookie publicbooleanisRequestedSessionIdFromCookie(); 如果这个请求的sessionid是通过客户端的一个cookie提供的,该方法返回真,否则返回假。 18、isRequestedSessionIdFromURL publicbooleanisRequestedSessionIdFromURL(); 如果这个请求的sessionid是通过客户端的URL的一部分提供的,该方法返回真,否则返回假。请注意此方法与isRequestedSessionIdFromUrl在URL的拼写上不同。 以下方法将被取消\\r 19、isRequestedSessionIdFromUrl publicbooleanisRequestedSessionIdFromUrl(); 该方法被isRequestedSessionIdFromURL代替。 二、HttpServletResponse接口 定义\\r publicinterfaceHttpServletResponseextendsServletResponse 描述一个返回到客户端的HTTP回应。这个接口允许Servlet程序员利用HTTP协议规定的头信息。 成员变量 publicstaticfinalintSC_CONTINUE=100; publicstaticfinalintSC_SWITCHING_PROTOCOLS=101; publicstaticfinalintSC_OK=200; publicstaticfinalintSC_CREATED=201; publicstaticfinalintSC_ACCEPTED=202; publicstaticfinalintSC_NON_AUTHORITATIVE_INFORMATION=203; publicstaticfinalintSC_NO_CONTENT=204; publicstaticfinalintSC_RESET_CONTENT=205; publicstaticfinalintSC_PARTIAL_CONTENT=206; publicstaticfinalintSC_MULTIPLE_CHOICES=300; publicstaticfinalintSC_MOVED_PERMANENTLY=301; publicstaticfinalintSC_MOVED_TEMPORARILY=302; publicstaticfinalintSC_SEE_OTHER=303; publicstaticfinalintSC_NOT_MODIFIED=304; publicstaticfinalintSC_USE_PROXY=305; publicstaticfinalintSC_BAD_REQUEST=400; publicstaticfinalintSC_UNAUTHORIZED=401; publicstaticfinalintSC_PAYMENT_REQUIRED=402; publicstaticfinalintSC_FORBIDDEN=403; publicstaticfinalintSC_NOT_FOUND=404; publicstaticfinalintSC_METHOD_NOT_ALLOWED=405; publicstaticfinalintSC_NOT_ACCEPTABLE=406; publicstaticfinalintSC_PROXY_AUTHENTICATION_REQUIRED=407; publicstaticfinalintSC_REQUEST_TIMEOUT=408; publicstaticfinalintSC_CONFLICT=409; publicstaticfinalintSC_GONE=410; publicstaticfinalintSC_LENGTH_REQUIRED=411; publicstaticfinalintSC_PRECONDITION_FAILED=412; publicstaticfinalintSC_REQUEST_ENTITY_TOO_LARGE=413; publicstaticfinalintSC_REQUEST_URI_TOO_LONG=414; publicstaticfinalintSC_UNSUPPORTED_MEDIA_TYPE=415; publicstaticfinalintSC_INTERNAL_SERVER_ERROR=500; publicstaticfinalintSC_NOT_IMPLEMENTED=501; publicstaticfinalintSC_BAD_GATEWAY=502; publicstaticfinalintSC_SERVICE_UNAVAILABLE=503; publicstaticfinalintSC_GATEWAY_TIMEOUT=504; publicstaticfinalintSC_HTTP_VERSION_NOT_SUPPORTED=505; 以上HTTP产状态码是由HTTP/1.1定义的。 方法 1、addCookie publicvoidaddCookie(Cookiecookie); 在响应中增加一个指定的cookie。可多次调用该方法以定义多个cookie。为了设置适当的头域,该方法应该在响应被提交之前调用。 2、containsHeader publicbooleancontainsHeader(Stringname); 检查是否设置了指定的响应头。 3、encodeRedirectURL publicStringencodeRedirectURL(Stringurl); 对sendRedirect方法使用的指定URL进行编码。如果不需要编码,就直接返回这个URL。之所以提供这个附加的编码方法,是因为在redirect的情况下,决定是否对URL进行编码的规则和一般情况有所不同。所给的URL必须是一个绝对URL。相对URL不能被接收,会抛出一个IllegalArgumentException。 所有提供给sendRedirect方法的URL都应通过这个方法运行,这样才能确保会话跟踪能够在所有浏览器中正常运行。 4、encodeURL publicStringencodeURL(Stringurl); 对包含sessionID的URL进行编码。如果不需要编码,就直接返回这个URL。Servlet引擎必须提供URL编码方法,因为在有些情况下,我们将不得不重写URL,例如,在响应对应的请求中包含一个有效的session,但是这个session不能被非URL的(例如cookie)的手段来维持。 所有提供给Servlet的URL都应通过这个方法运行,这样才能确保会话跟踪能够在所有浏览器中正常运行。 5、sendError publicvoidsendError(intstatusCode)throwsIOException; publicvoidsendError(intstatusCode,Stringmessage)throws IOException; 用给定的状态码发给客户端一个错误响应。如果提供了一个message参数,这将作为响应体的一部分被发出,否则,服务器会返回错误代码所对应的标准信息。 调用这个方法后,响应立即被提交。在调用这个方法后,Servlet不会再有更多的输出。 6、sendRedirect publicvoidsendRedirect(Stringlocation)throwsIOException; 使用给定的路径,给客户端发出一个临时转向的响应(SC_MOVED_TEMPORARILY)。给定的路径必须是绝对URL。相对URL将不能被接收,会抛出一个IllegalArgumentException。 这个方法必须在响应被提交之前调用。调用这个方法后,响应立即被提交。在调用这个方法后,Servlet不会再有更多的输出。 7、setDateHeader publicvoidsetDateHeader(Stringname,longdate); 用一个给定的名称和日期值设置响应头,这里的日期值应该是反映自1970-1-1日(GMT)以来的精确到毫秒的长整数。如果响应头已经被设置,新的值将覆盖当前的值。 8、setHeader publicvoidsetHeader(Stringname,Stringvalue); 用一个给定的名称和域设置响应头。如果响应头已经被设置,新的值将覆盖当前的值。 9、setIntHeader publicvoidsetIntHeader(Stringname,intvalue); 用一个给定的名称和整形值设置响应头。如果响应头已经被设置,新的值将覆盖当前的值。 10、setStatus publicvoidsetStatus(intstatusCode); 这个方法设置了响应的状态码,如果状态码已经被设置,新的值将覆盖当前的值。 以下的几个方法将被取消\ 11、encodeRedirectUrl publicStringencodeRedirectUrl(Stringurl); 该方法被encodeRedirectURL取代。 12、encodeUrl publicStringencodeUrl(Stringurl); 该方法被encodeURL取代。 13、setStatus publicvoidsetStatus(intstatusCode,Stringmessage); 这个方法设置了响应的状态码,如果状态码已经被设置,新的值将覆盖当前的值。如果提供了一个message,它也将会被作为响应体的一部分被发送。 三、HttpSession接口 定义\ publicinterfaceHttpSession 这个接口被Servlet引擎用来实现在HTTP客户端和HTTP会话两者的关联。这种关联可能在多外连接和请求中持续一段给定的时间。session用来在无状态的HTTP协议下越过多个请求页面来维持状态和识别用户。 一个session可以通过cookie或重写URL来维持。 方法 1、getCreationTime publiclonggetCreationTime(); 返回建立session的时间,这个时间表示为自1970-1-1日(GMT)以来的毫秒数。 2、getId publicStringgetId(); 返回分配给这个session的标识符。一个HTTPsession的标识符是一个由服务器来建立和维持的唯一的字符串。 3、getLastAccessedTime publiclonggetLastAccessedTime(); 返回客户端最后一次发出与这个session有关的请求的时间,如果这个session是新建立的,返回-1。这个时间表示为自1970-1-1日(GMT)以来的毫秒数。 4、getMaxInactiveInterval publicintgetMaxInactiveInterval(); 返加一个秒数,这个秒数表示客户端在不发出请求时,session被Servlet引擎维持的最长时间。在这个时间之后,Servlet引擎可能被Servlet引擎终止。如果这个session不会被终止,这个方法返回-1。 当session无效后再调用这个方法会抛出一个IllegalStateException。 5、getValue publicObjectgetValue(Stringname); 返回一个以给定的名字绑定到session上的对象。如果不存在这样的绑定,返回空值。 当session无效后再调用这个方法会抛出一个IllegalStateException。 6、getValueNames publicString[]getValueNames(); 以一个数组返回绑定到session上的所有数据的名称。 当session无效后再调用这个方法会抛出一个IllegalStateException。 7、invalidate publicvoidinvalidate(); 这个方法会终止这个session。所有绑定在这个session上的数据都会被清除。并通过HttpSessionBindingListener接口的valueUnbound方法发出通告。 8、isNew publicbooleanisNew(); 返回一个布尔值以判断这个session是不是新的。如果一个session已经被服务器建立但是还没有收到相应的客户端的请求,这个session将被认为是新的。这意味着,这个客户端还没有加入会话或没有被会话公认。在他发出下一个请求时还不能返回适当的session认证信息。 当session无效后再调用这个方法会抛出一个IllegalStateException。 9、putValue publicvoidputValue(Stringname,Objectvalue); 以给定的名字,绑定给定的对象到session中。已存在的同名的绑定会被重置。这时会调用HttpSessionBindingListener接口的valueBound方法。 当session无效后再调用这个方法会抛出一个IllegalStateException。 10、removeValue publicvoidremoveValue(Stringname); 取消给定名字的对象在session上的绑定。如果未找到给定名字的绑定的对象,这个方法什么出不做。这时会调用HttpSessionBindingListener接口的valueUnbound方法。 当session无效后再调用这个方法会抛出一个IllegalStateException。 11、setMaxInactiveInterval publicintsetMaxInactiveInterval(intinterval); 设置一个秒数,这个秒数表示客户端在不发出请求时,session被Servlet引擎维持的最长时间。 以下这个方法将被取消\ 12、getSessionContext publicHttpSessionContextgetSessionContext(); 返回session在其中得以保持的环境变量。这个方法和其他所有HttpSessionContext的方法一样被取消了。 四、HttpSessionBindingListener接口 定义\ publicinterfaceHttpSessionBindingListener 这个对象被加入到HTTP的session中,执行这个接口会通告有没有什么对象被绑定到这个HTTPsession中或被从这个HTTPsession中取消绑定。 方法 1、valueBound publicvoidvalueBound(HttpSessionBindingEventevent); 当一个对象被绑定到session中,调用此方法。HttpSession.putValue方法被调用时,Servlet引擎应该调用此方法。 2、valueUnbound publicvoidvalueUnbound(HttpSessionBindingEventevent); 当一个对象被从session中取消绑定,调用此方法。HttpSession.removeValue方法被调用时,Servlet引擎应该调用此方法。 五、HttpSessionContext接口 定义\ 此接口将被取消\ publicinterfaceHttpSessionContext 这个对象是与一组HTTPsession关联的单一的实体。 这个接口由于安全的原因被取消,它出现在目前的版本中仅仅是为了兼容性的原因。这个接口的方法将模拟以前的版本的定义返回相应的值。 方法 1、getSession publicHttpSessiongetSession(StringsessionId); 当初用来返回与这个sessionid相关的session。现在返回空值。 2、getIds publicEnumerationgetIds(); 当初用来返回这个环境下所有sessionid的列表。现在返回空的列表。 六、Cookie类\ 定义\ publicclassCookieimplementsCloneable 这个类描述了一个cookie,有关cookie的定义你可以参照NetscapeCommunicationsCorporation的说明,也可以参照RFC2109。 构造函数 publicCookie(Stringname,Stringvalue); 用一个name-value对定义一个cookie。这个name必须能被HTTP/1.1所接受。 以字符$开头的name被RFC2109保留。 给定的name如果不能被HTTP/1.1所接受,该方法抛出一个IllegalArgumentException。 方法 1、getComment publicStringgetComment(); 返回描述这个cookie目的的说明,如果未定义这个说明,返回空值。 2、getDomain publicStringgetDomain(); 返回这个cookie可以出现的区域,如果未定义区域,返回空值。 3、getMaxAge publicintgetMaxAge(); 这个方法返回这个cookie指定的最长存活时期。如果未定义这个最长存活时期,该方法返回-1。 4、getName publicStringgetName(); 该方法返回cookie名。 5、getPath publicStringgetPath(); 返回这个cookie有效的所有URL路径的前缀,如果未定义,返回空值。 6、getSecure publicbooleangetSecure(); 如果这个cookie只通过安全通道传输返回真,否则返回假。 7、getValue publicStringgetValue(); 该方法返回cookie的值。 8、getVersion publicintgetVersion(); 返回cookie的版本。版本1由RFC2109解释。版本0由NetscapeCommunicationsCorporation的说明解释。新构造的cookie默认使用版本0。 9、setComment publicvoidsetComment(Stringpurpose); 如果一个用户将这个cookie提交给另一个用户,必须通过这个说明描述这个cookie的目的。版本0不支持这个属性。 10、setDomain publicvoidsetDomain(Stringpattern); 这个方法设置cookie的有效域的属性。这个属性指定了cookie可以出现的区域。一个有效域以一个点开头(.foo.com),这意味着在指定的域名解析系统的区域中(可能是www.foo.com但不是a.b.foo.com)的主机可以看到这个cookie。默认情况是,cookie只能返回保存它的主机。 11、setMaxAge publicvoidsetMaxAge(intexpiry); 这个方法设定这个cookie的最长存活时期。在该存活时期之后,cookie会被终目。负数表示这个cookie不会生效,0将从客户端删除这个cookie。 12、setPath publicvoidsetPath(Stringuri); 这个方法设置cookie的路径属性。客户端只能向以这个给定的路径String开头的路径返回cookie。 13、setSecure publicvoidsetSecure(booleanflag); 指出这个cookie只能通过安全通道(例如HTTPS)发送。只有当产生这个cookie的服务器使用安全协议发送这个cookie值时才能这样设置。 14、setValue publicvoidsetValue(StringnewValue); 设置这个cookie的值,对于二进制数据采用BASE64编码。 版本0不能使用空格、{}、()、=、,、“”、/、?、@、:以及;。 15、setVersion publicvoidsetVersion(intv); 设置cookie的版本号 七、HttpServlet类\ 定义\ publicclassHttpServletextendsGenericServletimplements Serializable 这是一个抽象类,用来简化HTTPServlet写作的过程。它是GenericServlet类的扩充,提供了一个处理HTTP协议的框架。 在这个类中的service方法支持例如GET、POST这样的标准的HTTP方法。这一支持过程是通过分配他们到适当的方法(例如doGet、doPost)来实现的。 方法 1、doDelete protectedvoiddoDelete(HttpServletRequestrequest, HttpServletResponseresponse)throwsServletException, IOException; 被这个类的service方法调用,用来处理一个HTTPDELETE操作。这个操作允许客户端请求从服务器上删除URL。这一操作可能有负面影响,对此用户就负起责任。 这一方法的默认执行结果是返回一个HTTPBAD_REQUEST错误。当你要处理DELETE请求时,你必须重载这一方法。 2、doGet protectedvoiddoGet(HttpServletRequestrequest, HttpServletResponseresponse)throwsServletException, IOException; 被这个类的service方法调用,用来处理一个HTTPGET操作。这个操作允许客户端简单地从一个HTTP服务器“获得”资源。对这个方法的重载将自动地支持HEAD方法。 GET操作应该是安全而且没有负面影响的。这个操作也应该可以安全地重复。 这一方法的默认执行结果是返回一个HTTPBAD_REQUEST错误。 3、doHead protectedvoiddoHead(HttpServletRequestrequest, HttpServletResponseresponse)throwsServletException, IOException; 被这个类的service方法调用,用来处理一个HTTPHEAD操作。默认的情况是,这个操作会按照一个无条件的GET方法来执行,该操作不向客户端返回任何数据,而仅仅是返回包含内容长度的头信息。 与GET操作一样,这个操作应该是安全而且没有负面影响的。这个操作也应该可以安全地重复。 这个方法的默认执行结果是自动处理HTTPHEAD操作,这个方法不需要被一个子类执行。 4、doOptions protectedvoiddoOptions(HttpServletRequestrequest, HttpServletResponseresponse)throwsServletException, IOException; 被这个类的service方法调用,用来处理一个HTTPOPTION操作。这个操作自动地决定支持哪一种HTTP方法。例如,一个Servlet写了一个HttpServlet的子类并重载了doGet方法,doOption会返回下面的头: Allow:GET,HEAD,TRACE,OPTIONS 你一般不需要重载这个方法。 5、doPost protectedvoiddoPost(HttpServletRequestrequest, HttpServletResponseresponse)throwsServletException, IOException; 被这个类的service方法调用,用来处理一个HTTPPOST操作。这个操作包含请求体的数据,Servlet应该按照他行事。 这个操作可能有负面影响。例如更新存储的数据或在线购物。 这一方法的默认执行结果是返回一个HTTPBAD_REQUEST错误。当你要处理POST操作时,你必须在HttpServlet的子类中重载这一方法。 6、doPut protectedvoiddoPut(HttpServletRequestrequest, HttpServletResponseresponse)throwsServletException, IOException; 被这个类的service方法调用,用来处理一个HTTPPUT操作。这个操作类似于通过FTP发送文件。 这个操作可能有负面影响。例如更新存储的数据或在线购物。 这一方法的默认执行结果是返回一个HTTPBAD_REQUEST错误。当你要处理PUT操作时,你必须在HttpServlet的子类中重载这一方法。 7、doTrace protectedvoiddoTrace(HttpServletRequestrequest, HttpServletResponseresponse)throwsServletException, IOException; 被这个类的service方法调用,用来处理一个HTTPTRACE操作。这个操作的默认执行结果是产生一个响应,这个响应包含一个反映trace请求中发送的所有头域的信息。 当你开发Servlet时,在多数情况下你需要重载这个方法。 8、getLastModified protectedlonggetLastModified(HttpServletRequestrequest); 返回这个请求实体的最后修改时间。为了支持GET操作,你必须重载这一方法,以精确地反映最后修改的时间。这将有助于浏览器和代理服务器减少装载服务器和网络资源,从而更加有效地工作。返回的数值是自1970-1-1日(GMT)以来的毫秒数。 默认的执行结果是返回一个负数,这标志着最后修改时间未知,它也不能被一个有条件的GET操作使用。 9、service protectedvoidservice(HttpServletRequestrequest, HttpServletResponseresponse)throwsServletException, IOException; publicvoidservice(ServletRequestrequest,ServletResponseresponse) throwsServletException,IOException; 这是一个Servlet的HTTP-specific方案,它分配请求到这个类的支持这个请求的其他方法。 当你开发Servlet时,在多数情况下你不必重载这个方法。 八、HttpSessionBindingEvent类\ 定义\ publicclassHttpSessionBindingEventextendsEventObject 这个事件是在监听到HttpSession发生绑定和取消绑定的情况时连通HttpSessionBindingListener的。这可能是一个session被终止或被认定无效的结果。 事件源是HttpSession.putValue或HttpSession.removeValue。 构造函数 publicHttpSessionBindingEvent(HttpSessionsession,Stringname); 通过引起这个事件的Session和发生绑定或取消绑定的对象名构造一个新的HttpSessionBindingEvent。 方法 1、getName publicStringgetName(); 返回发生绑定和取消绑定的对象的名字。 2、getSession publicHttpSessiongetSession(); 返回发生绑定和取消绑定的session的名字。 九、HttpUtils类\ 定义\ publicclassHttpUtils 收集HTTPServlet使用的静态的有效的方法。 方法 1、getRequestURL publicstaticStringBuffergetRequestURL(HttpServletRequest request); 在服务器上重建客户端用来建立请求的URL。这个方法反映了不同的协议(例如http和https)和端口,但不包含查询字符串。 这个方法返回一个StringBuffer而不是一个String,这样URL可以被Servlet开发者有效地修改。 2、parsePostData publicstaticHashtableparsePostData(intlen, ServletInputstreamin); 解析一个包含MIME类型application/x-www-form-urlencoded的数据的流,并创建一个具有关键值-数据对的hashtable。这里的关键值是字符串,数据是该字符串所对应的值的列表。一个关键值可以在POST的数据中出现一次或多次。这个关键值每出现一次,它的相应的值就被加入到hashtable中的字符串所对应的值的列表中。 从POST数据读出的数据将经过URL解码,+将被转换为空格以十六进制传送的数据(例如%xx)将被转换成字符。 当POST数据无效时,该方法抛出一个IllegalArgumentException。 3、parseQueryString publicstaticHashtableparseQueryString(Strings); 解析一个查询字符串,并创建一个具有关键值-数据对的hashtable。这里的数据是该字符串所对应的值的列表。一个关键值可以出现一次或多次。这个关键值每出现一次,它的相应的值就被加入到hashtable中的字符串所对应的值的列表中。 从查询字符串读出的数据将经过URL解码,+将被转换为空格以十六进制传送的数据(例如%xx)将被转换成字符。 当查询字符串无效时,该方法抛出一个IllegalArgumentException。 bytecode 字节码:由Java编译器和Java解释程序生成的机器代码。 cookie 由Web服务器建立的数据,该数据存储在用户的计算机上,提供了一个Web站点跟踪用户的参数并存储在用户自己硬盘上的方法。 HTTP 超文本传输协议。一个请求响应协议用来连接WWW服务器向客户端浏览器传输HTML页面。 输入流对象\r 一个对象,由ServletInputStream类定义,被Servlet用来从客户端读取请求。 映射\r 由Servlet实例和Servlet返回数据的URL组成的一对,例如,HelloServlet和/hello/index.html。 输出流对象\r 一个对象,由ServletOutputStreamclass类定义,被Servlet用来向客户端返回数据。 requestdispatcherobject 由RequestDispatcher接口定义的一个对象,用来从客户端接收请求,并将其发送到Web服务器上可用的其他资源(例如Servlet、CGI、HTML文件或JSP文件)。 sandboxedservlet 在一个安全性约束下运行的Servlet。 servlet 一个小的,具有平台无关性的,没有图形用户界面的Java程序。它可以在许多方面扩充Web服务的功能。 servletconfigurationobject ServletConfig接口定义的一个对象,用来配置一个Servlet。 servletcontextobject ServletContext接口定义的一个对象。给予Servlet有关Servlet引擎的信息。 servlet引擎\r 由Web服务器提供商制作的一个环境,可以允许Servlet在具体的Web服务器上运行。 servlet请求对象 由ServletRequest接口定义的一个对象,允许Servlet获得用关客户端请求的数据。 servletresponseobject 由ServletResponse接口定义的一个对象,允许Servlet作出响应。 servletrunner JavaServletDeveloper’sKit(JSDK)中的sun.servlet.http.HttpServer过程,它使得Servlet得以运行。 会话跟踪 在一个Web应用程序中,识别一个从同一个客户端发出的连续的唯一的请求的能力。 SSL 加密套接字协议层。一个安全协议,用来在Iternet上的客户端浏览器和服务器交换密钥和加密数据。 URI 统一资源标识。定义一个Internet地址,它是一个URL的超集。 URL 统一资源路径。这个地址定义了到达一个WWW上的文件的路线,通常由协议前缀、域名、目录名和文件名组成。
jsp内置对象 定义:可以不加声明就在JSP页面脚本(Java程序片和Java表达式)中使用的成员变量   JSP共有以下9种基本内置组件(可与ASP的6种内部组件相对应):    1.request对象    客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。    序号 方 法 说 明    1 object getAttribute(String name) 返回指定属性的属性值    2 Enumeration getAttributeNames() 返回所有可用属性名的枚举    3 String getCharacterEncoding() 返回字符编码方式    4 int getContentLength() 返回请求体的长度(以字节数)    5 String getContentType() 得到请求体的MIME类型    6 ServletInputStream getInputStream() 得到请求体中一行的二进制流    7 String getParameter(String name) 返回name指定参数的参数值    8 Enumeration getParameterNames() 返回可用参数名的枚举    9 String[] getParameterValues(String name) 返回包含参数name的所有值的数组    10 String getProtocol() 返回请求用的协议类型及版本号    11 String getScheme() 返回请求用的计划名,如:http.https及ftp等    12 String getServerName() 返回接受请求的服务器主机名    13 int getServerPort() 返回服务器接受此请求所用的端口号    14 BufferedReader getReader() 返回解码过了的请求体    15 String getRemoteAddr() 返回发送此请求的客户端IP地址    16 String getRemoteHost() 返回发送此请求的客户端主机名    17 void setAttribute(String key,Object obj) 设置属性的属性值    18 String getRealPath(String path) 返回一虚拟路径的真实路径    2.response对象    response对象包含了响应客户请求的有关信息,但在JSP中很少直接用到它。它是HttpServletResponse类的实例。    序号 方 法 说 明    1 String getCharacterEncoding() 返回响应用的是何种字符编码    2 ServletOutputStream getOutputStream() 返回响应的一个二进制输出流    3 PrintWriter getWriter() 返回可以向客户端输出字符的一个对象    4 void setContentLength(int len) 设置响应头长度    5 void setContentType(String type) 设置响应的MIME类型    6 sendRedirect(java.lang.String location) 重新定向客户端的请求    3.session对象    session对象指的是客户端与服务器的一次会话,从客户端连到服务器的一个WebApplication开始,直到客户端与服务器断开连接为止。它是HttpSession类的实例.    序号 方 法 说 明    1 long getCreationTime() 返回SESSION创建时间    2 public String getId() 返回SESSION创建时JSP引擎为它设的惟一ID号    3 long getLastAccessedTime() 返回此SESSION里客户端最近一次请求时间    4 int getMaxInactiveInterval() 返回两次请求间隔多长时间此SESSION被取消(ms)    5 String[] getValueNames() 返回一个包含此SESSION中所有可用属性的数组    6 void invalidate() 取消SESSION,使SESSION不可用    7 boolean isNew() 返回服务器创建的一个SESSION,客户端是否已经加入    8 void removeValue(String name) 删除SESSION中指定的属性    9 void setMaxInactiveInterval() 设置两次请求间隔多长时间此SESSION被取消(ms)    4.out对象    out对象是JspWriter类的实例,是向客户端输出内容常用的对象    序号 方 法 说 明    1 void clear() 清除缓冲区的内容    2 void clearBuffer() 清除缓冲区的当前内容    3 void flush() 清空流    4 int getBufferSize() 返回缓冲区以字节数的大小,如不设缓冲区则为0    5 int getRemaining() 返回缓冲区还剩余多少可用    6 boolean isAutoFlush() 返回缓冲区满时,是自动清空还是抛出异常    7 void close() 关闭输出流    5.page对象    page对象就是指向当前JSP页面本身,有点象类中的this指针,它是java.lang.Object类的实例    序号 方 法 说 明    1 class getClass 返回此Object的类    2 int hashCode() 返回此Object的hash码    3 boolean equals(Object obj) 判断此Object是否与指定的Object对象相等    4 void copy(Object obj) 把此Object拷贝到指定的Object对象中    5 Object clone() 克隆此Object对象    6 String toString() 把此Object对象转换成String类的对象    7 void notify() 唤醒一个等待的线程    8 void notifyAll() 唤醒所有等待的线程    9 void wait(int timeout) 使一个线程处于等待直到timeout结束或被唤醒    10 void wait() 使一个线程处于等待直到被唤醒    11 void enterMonitor() 对Object加锁    12 void exitMonitor() 对Object开锁    6.application对象 application对象实现了用户间数据的共享,可存放全局变量。它开始于服务器的启动, 直到服务器的关闭,在此期间,此对象将一直存在;这样在用户的前后连接或不同用户之间的连接中,可以对此对象的同一属性进行操作;在任何地方对此对象属性 的操作,都将影响到其他用户对此的访问。服务器的启动和关闭决定了application对象的生命。它是ServletContext类的实例。    序号 方 法 说 明    1 Object getAttribute(String name) 返回给定名的属性值    2 Enumeration getAttributeNames() 返回所有可用属性名的枚举    3 void setAttribute(String name,Object obj) 设定属性的属性值    4 void removeAttribute(String name) 删除一属性及其属性值    5 String getServerInfo() 返回JSP(SERVLET)引擎名及版本号    6 String getRealPath(String path) 返回一虚拟路径的真实路径    7 ServletContext getContext(String uripath) 返回指定WebApplication的application对象    8 int getMajorVersion() 返回服务器支持的Servlet API的最大版本号    9 int getMinorVersion() 返回服务器支持的Servlet API的最大版本号    10 String getMimeType(String file) 返回指定文件的MIME类型    11 URL getResource(String path) 返回指定资源(文件及目录)的URL路径    12 InputStream getResourceAsStream(String path) 返回指定资源的输入流    13 RequestDispatcher getRequestDispatcher(String uripath) 返回指定资源的RequestDispatcher对象    14 Servlet getServlet(String name) 返回指定名的Servlet    15 Enumeration getServlets() 返回所有Servlet的枚举    16 Enumeration getServletNames() 返回所有Servlet名的枚举    17 void log(String msg) 把指定消息写入Servlet的日志文件    18 void log(Exception exception,String msg) 把指定异常的栈轨迹及错误消息写入Servlet的日志文件    19 void log(String msg,Throwable throwable) 把栈轨迹及给出的Throwable异常的说明信息 写入Servlet的日志文件    7.exception对象    exception对象是一个例外对象,当一个页面在运行过程中发生了例外,就产生这个对象。如果一个JSP页面要应用此对象,就必须把isErrorPage设为true,否则无法编译。他实际上是java.lang.Throwable的对象    序号 方 法 说 明    1 String getMessage() 返回描述异常的消息    2 String toString() 返回关于异常的简短描述消息    3 void printStackTrace() 显示异常及其栈轨迹    4 Throwable FillInStackTrace() 重写异常的执行栈轨迹    8.pageContext对象    pageContext对象提供了对JSP页面内所有的对象及名字空间的访问,也就是说他可以访问到本页所在的SESSION,也可以取本页面所在的application的某一属性值,他相当于页面中所有功能的集大成者,它的本类名也叫pageContext。    序号 方 法 说 明    1 JspWriter getOut() 返回当前客户端响应被使用的JspWriter流(out)    2 HttpSession getSession() 返回当前页中的HttpSession对象(session)    3 Object getPage() 返回当前页的Object对象(page)    4 ServletRequest getRequest() 返回当前页的ServletRequest对象(request)    5 ServletResponse getResponse() 返回当前页的ServletResponse对象(response)    6 Exception getException() 返回当前页的Exception对象(exception)    7 ServletConfig getServletConfig() 返回当前页的ServletConfig对象(config)    8 ServletContext getServletContext() 返回当前页的ServletContext对象(application)    9 void setAttribute(String name,Object attribute) 设置属性及属性值    10 void setAttribute(String name,Object obj,int scope) 在指定范围内设置属性及属性值    11 public Object getAttribute(String name) 取属性的值    12 Object getAttribute(String name,int scope) 在指定范围内取属性的值    13 public Object findAttribute(String name) 寻找一属性,返回起属性值或NULL    14 void removeAttribute(String name) 删除某属性    15 void removeAttribute(String name,int scope) 在指定范围删除某属性    16 int getAttributeScope(String name) 返回某属性的作用范围    17 Enumeration getAttributeNamesInScope(int scope) 返回指定范围内可用的属性名枚举    18 void release() 释放pageContext所占用的资源    19 void forward(String relativeUrlPath) 使当前页面重导到另一页面    20 void include(String relativeUrlPath) 在当前位置包含另一文件    9.config对象    config对象是在一个Servlet初始化时,JSP引擎向它传递信息用的,此信息包括Servlet初始化时所要用到的参数(通过属性名和属性值构成)以及服务器的有关信息(通过传递一个ServletContext对象)    序号 方 法 说 明    1 ServletContext getServletContext() 返回含有服务器相关信息的ServletContext对象    2 String getInitParameter(String name) 返回初始化参数的值    3 Enumeration getInitParameterNames() 返回Servlet初始化所需所有参数的枚举

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧