国外的一些struts面试题2

这篇文章实在是翻译得腻了,反正就是写着玩,后面没怎么用心。错的地方见谅。

Q:What is RequestProcessor and RequestDispatcher?

      什么是请求处理器和请求转发?

A:The controller is responsible for intercepting and translating user input into actions to be performed by the model. The controller is responsible for selecting the next view based on user input and the outcome of model operations. The Controller receives the request from the browser, invoke a business operation and coordinating the view to return to the client.

      模型控制器有责任去侦听和转换用户操作。控制器有责任根据用户输入和模型操作返回挑选下一步显示内容。控制器从浏览器接受请求,调用业务操作,并调整返回客户端显示。

   The controller is implemented by a java servlet, this servlet is centralized point of control for the web application. In struts framework the controller responsibilities are implemented by serveral different components like The ActionServlet Class,The RequestProcessor Class,The Action Class

      控制器通过java服务器端程序实现。这个服务器端程序集中网络应用的控制。在struts框架控制器的责任来自于实现不同的成分。例如:The ActionServlet Class、The RequestProcessor Class、The Action Class

   The ActionServlet extends the javax.servlet.http.httpServlet class. The ActionServlet class is not abstract and therefore can be used as a concrete controller by your application.

   ActionServlet继承 javax.servlet.http.httpServlet类。ActionServlet类不是抽象的, 所以可盈被用来做应用程序的具体控制器。

   The controller is implemented by the ActionServlet class. All incoming requests are mapped to the central controller in the deployment descriptor as follows.

   控制器由ActionServlet类实现。所有来的请求路径安排都由中央控制器描述部署。如下所示:

<servlet>
   <servlet-name>action</servlet-name>
   <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
</servlet>
   All request URls with the pattern *.do are mapped to this servlet in the deployment descriptor as follows.

   所有请求带有*.do的给服务器的请求路径都如下部署描述:

<servlet-mapping>
   <servlet-name>action</servlet-name>
   <url-pattern>*.do</url-pattern>
<pre name="code" class="html">   <url-pattern>*.do</url-pattern>
</servlet-mapping>

 

   A request URL that matches the pattern will have the following form:

   一个符合模式的请求连接如下所示:

http://www.my_site_name.com/mycontext/actionName.do

   The preceding mapping is called extension mapping, however, you can also specifends with /* as show below.

    前面的路径叫扩展路径,但是,你也可以特别用/*显示,如下:

<servlet-mapping>
   <servlet-name>action</servlet-name>
   <url-pattern>/do/*</url-pattern>
   <url-pattern>*.do</url-pattern>
</servlet-mapping>

   A request URL that matches this pattern will have the following form:

   一个符合模板的请求链接如下所示:

http://www.my_site_name.com/mycontext/do/action_Name

   The class org.apache.struts.action.requestProcessor process the request from the controller. You can subclass the RequestProcessor with your own version and modify how the request is processed.

      类org.apache.struts.action.requestProcessor是控制器请求的处理流程。你可以用自己的版本的子类,修改请求处理流程。

      Once the controller receives a client request, it delegates the handling of the request to helper class. This helper knows how to execute the business operation associated with the requested action. In the Struts framework this helper class is descended of org.apache.struts.action.Action class. It acts as a bridge between a client-side user action and business operation. The Action class decouples the client request from the business model. This decoupling allows for more than one-to one mapping between the user request and an action. The Action class also can perform other functions such as authorization, logging before invoking business operation. the Struts Action class contains erveral methods, but most important method is the execute() method.

       当控制器接收到客户端请求,它把对请求的操作委派给一个辅助类。这个辅助类知道如何与请求行动相关执行业务操作。在struts框架中这个辅助类需要继承org.apache.struts.action.Action类。它在用户客户端操作和业务操作间扮演桥梁的角色。Action类从业务模型中解耦客户端请求。这个解耦允许更多一对一路径在用户请求和执行之间。Struts Action类包含一些方法,但是最重要的方法是execute()方法。

   public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception;

   The execute() method is called by the controller when a request is received from a client. The controller creates an instance of the Action class if one doesn't already exist. The struts framework will create only a single instance of each Action class in your application.

    当控制器接受到从客户端传来的请求执行execute()方法。控制器创建Action类的实例,如果没有的话。Struts框架将在应用程序中为每个Action类创建一个单一的实例。

   Action are mapped in the struts configuration file and this configuration is loaded into memory at startup and made available to the framework at runtime. Each Action element is represente in memory by an instance of the org.apache.struts.action.ActionMapping class. The ActionMapping object contains a path attribute that is match against a portion of the URL of the incoming request.

   在框架可用并开始运行时,struts的Action路径就已经配置好,并写入内存中。每个Action元素在内存中以org.apache.struts.action.ActionMapping类的实例表现。ActionMapping对象包含一个路径与输入的URL请求部分想匹配关联。

<action path="/somerequest" type="com.somepackage.someAction" scope="request" name="someForm" validate="true" input="somejsp.jsp">
   <forward name="success" path="/action/xys" redirect="true" />
   <forward name="fail" path="/somejsp.jsp" redirect="true" />
</action>
   Once this is done the controller should determine which view to return th the client. The execute method signature in cction class has a return type org.apache.struts.action.ActionForward class. The ActionForward class represents a destination to which the controller may send control once an action has completed. Instead of specifying an actual JSP page in the code. you can declaratively associate as action forward through out the application. The action forward are specified in the configuration file.

    做完这个后控制器会决定返回给客户端哪个视图。在类Action中名称为execute方法需要返回 org.apache.struts.action.ActionForward类值。当一个控制器控制的action结束后类ActionForward标识其目的地。你可以声明指向action,而取代指明具体的JSP页面。

<action path="/somerequest" type="com.somepackage.someAction" scope="request" name="someForm" validate="true" input="somejsp.jsp">
   <forward name="success" path="/action/xys" redirect="true" />
   <forward name="fail" path="/somejsp.jsp" redirect="true" />
</action>
   The action forward mappings also can be specified in global section independent of any specific action mapping.

   如果特别指定,路径也可以描述为全局范围。  

<global-forwards>
   <forward name="success" path="/action/somejsp.jsp" />
   <forward name="fail" path="/somejsp.jsp" />
</global-forwards>
public interface RequestDispatcher

   Defines an object that receives requests from the client and sends them to any resource(such as servlet,HTML file, or JSP file) on the server. The servlet container creates the RequestDispatcher objet, which is used as a wrapper around a server resource located at a particular path or given by a particular name.

   定义一个项目,它在服务器端接收客户端请求并将其发送给资源(像服务器,HTML文件,JSP文件)。服务器容器创建RequestDispatcher对象,它通过特定路径或定义特定名称封装本地化服务器资源。

   This interface is intended to wrap servlets, but a servlet container can create RequestDispatcher objects to wrap any type of resource.

   这个借口尝试包装服务,但是服务容器可以创建RequestDispatcher对象去包装任何类型的资源。

getRequestDispatcher : public RequestDispatcher getRequestDispatcher(java.lang.String path)

   Retruns a RequestDispatcher object that acts as a wrapper for the resource located at the given path. A RequestDispathcer object can be used to forward a request to the resource or to include the resource in a response.The resource can be dynamic or static.

   返回在本地给定路径包装后的资源的RequestDispatcher对象。RequestDispatcher对象可以用来指向请求或者在一个应答中包含资源。这个资源可以是静态或动态的。

   The pathname must begin with a "/" and is interpereted as relative to the current context root. Use getContext obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.

   路径名称必须以/开头,被视为以现在环境路径为基本路径。在其他环境下用getContext获得资源的RequestDispatcher.当ServletContext不能返回RequestDispatcher返回null.

Parameters : 参数

path - a String specifying the pathname to the resource.字符串为资源指定路径名称。

Returns : 返回

a RequestDispatcher object that acts as a wrapper for the resource at the specified path.指定路径的资源包作为RequestDispatcher对象返回。

See Also:

RequestDispatcher,getContext(java.lang.String)


getNameDispatcher

public RequestDispatcher getNameDispatcher(java.lang.String name)


   Returns a RequestDispatcher object that acts as a wrapper for the named servlet.

    返回RequestDispatcher对象,被命名的服务包。

   Servlets(and JSP pages also) may be given names via server administration or via a web application deployment descriptor. Aervlet instance can detemine its name using ServletConfig.getServletName(). This method returns null if the ServletContext cannot return a RequestDispatcher for any reason.

    服务(JSP页面同样)可能被给名字通过服务器管理员,或通过开发者。一个服务器实力可以通过ServletConfig.getServletName()来指定名字。

   This method returns null if the ServletContext cannot return a RequestDispatcher for any reason.

    如果ServletContext不能返回RequestDispatcher则返回null.


Parameters : 参数

name - a String specifying the name of a servlet to wrap.字符串,服务器包的名字。

Returns :  返回值

a RequestDispatcher object that acts as a wrapper for the named servlet. RequestDispatcher对象,作为服务器的包。

See Also :

RequestDispatcher, getContext(java.lang.String), ServletConfig.getServletName()

  


      

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值