<!-- -->
| JavaTM 2 Platform Ent. Ed. v1.4 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> All Classes <noscript></noscript> | |||||||||
| SUMMARY:NESTED|FIELD|CONSTR|METHOD | DETAIL:FIELD|CONSTR|METHOD | |||||||||
javax.servlet
Interface RequestDispatcher
-
public interface 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. The servlet container creates the RequestDispatcher object, which is used as a wrapper around a server resource located at a particular path or given by a particular name. 定义了一个对象用来接收客户端的请求,将它们发送给服务器上的任何资源(比如servlet,HTML文件,或者JSP文件)。 servlet容器创建了RequestDispatcher对象,用于包装以特定路径或特定名称定位的服务器资源。
This interface is intended to wrap servlets, but a servlet container can create RequestDispatcher objects to wrap any type of resource. 该接口目的是包装servlet,但是servlet容器创建的RequestDispatcher可以包装任何类型的资源。
-
Version:
- $Version$ Author:
- Various See Also:
-
ServletContext.getRequestDispatcher(java.lang.String),ServletContext.getNamedDispatcher(java.lang.String),ServletRequest.getRequestDispatcher(java.lang.String)
<!-- ======== NESTED CLASS SUMMARY ======== --><!-- =========== FIELD SUMMARY =========== --><!-- ======== CONSTRUCTOR SUMMARY ======== --><!-- ========== METHOD SUMMARY =========== --><!-- -->
| Method Summary | |
void | forward(ServletRequestrequest, ServletResponseresponse) Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. 从servlet向服务器上其他资源(servlet,JSP文件或者HTML文件)转发请求。 |
void | include(ServletRequestrequest, ServletResponseresponse) Includes the content of a resource (servlet, JSP page, HTML file) in the response. 包含响应中的资源(servlet,JSP文件,HTML文件)内容。 |
<!-- ============ FIELD DETAIL =========== --><!-- ========= CONSTRUCTOR DETAIL ======== --><!-- ============ METHOD DETAIL ========== --><!-- -->
| Method Detail |
forward
-
Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. This method allows one servlet to do preliminary processing of a request and another resource to generate the response. 从servlet向服务器上其他资源(servlet,JSP文件或者HTML文件)转发请求。该方法允许请求和其他资源生成响应之前做一些预处理。
For a
RequestDispatcherobtained viagetRequestDispatcher(), theServletRequestobject has its path elements and parameters adjusted to match the path of the target resource. 对于通过getRequestDispatcher()获得的RequestDispatcher,ServletRequest对象可以调整路径组成和参数来匹配目标资源的路径。forwardshould be called before the response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws anIllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward. forward应当在响应提交给客户端之前调用(响应体输出被刷新前)。如果响应已经被提交,该方法抛出IllegalStateException。响应缓存中未提交的输出在转发之前自动清空。The request and response parameters must be either the same objects as were passed to the calling servlet's service method or be subclasses of the
ServletRequestWrapperorServletResponseWrapperclasses that wrap them. 传递给调用servlet的service方法的请求和响应参数可以是相同的对象,也可以是 对它们进行包装的ServletRequestWrapper或ServletResponseWrapper类的子类。 -
-
Parameters:
-
request- aServletRequestobject that represents the request the client makes of the servlet ServletRequest对象,表示客户端向servlet发出的请求 -
response- aServletResponseobject that represents the response the servlet returns to the client ServletResponse对象,表示servlet返回给客户端的响应
Throws:
-
ServletException- if the target resource throws this exception 如果目标资源抛出该异常时抛出 -
IOException- if the target resource throws this exception 如果目标资源抛出该异常时抛出 -
IllegalStateException- if the response was already committed 如果响应已经提交则抛出
-
include
-
Includes the content of a resource (servlet, JSP page, HTML file) in the response. In essence, this method enables programmatic server-side includes. 包含响应中的资源(servlet,JSP文件,HTML文件)内容。本质上,该方法使服务器端包含成为可能。
The
ServletResponseobject has its path elements and parameters remain unchanged from the caller's. The included servlet cannot change the response status code or set headers; any attempt to make a change is ignored. 来自调用者的ServletResponse对象的路径组成和参数保持不变。包含的servlet 不能改变响应状态代码或设置头;任何变更的企图都会被忽略。The request and response parameters must be either the same objects as were passed to the calling servlet's service method or be subclasses of the
ServletRequestWrapperorServletResponseWrapperclasses that wrap them. 传递给调用servlet的service方法的请求和响应参数可以是相同的对象,也可以是 对它们进行包装的ServletRequestWrapper或ServletResponseWrapper类的子类。 -
-
Parameters:
-
request- aServletRequestobject that contains the client's request ServletRequest对象,表示客户端请求 -
response- aServletResponseobject that contains the servlet's response ServletResponse对象,表示servlet响应
Throws:
-
ServletException- if the included resource throws this exception 如果包含的资源抛出该异常时抛出 -
IOException- if the included resource throws this exception 如果包含的资源抛出该异常时抛出
-
<!-- -->
| JavaTM 2 Platform Ent. Ed. v1.4 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES <!-- if(window==top) { document.writeln('<A HREF="../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--> All Classes <noscript></noscript> | |||||||||
| SUMMARY:NESTED|FIELD|CONSTR|METHOD | DETAIL:FIELD|CONSTR|METHOD | |||||||||
Copyright 2003 Sun Microsystems, Inc. All rights reserved.
本文详细介绍了RequestDispatcher接口的功能,它是如何被servlet容器创建并用于转发客户端请求到服务器上的资源,如servlet、HTML文件或JSP文件。此外,还阐述了其两个核心方法:forward和include的工作原理。
237

被折叠的 条评论
为什么被折叠?



