简体   繁体   English

定制控制器

[英]Customizing controller

While reading Struts2 documentation, I encountered the passage as quoted below 在阅读Struts2文档时,我遇到了以下引文

customizing controller - Struts 1 lets to customize the request processor per module, Struts 2 lets to customize the request handling per action, if desired. 定制控制器-Struts 1允许自定义每个模块的请求处理器,Struts 2允许自定义每个操作的请求处理(如果需要)。

What do the author exactly mean. 作者究竟是什么意思。 Simple examples in code form for the demonstration on both will be appreciated 以代码形式进行简单演示的简单示例将不胜感激

Thanks in advance 提前致谢

Daniel 丹尼尔

Example of customizing the request processor in Struts 1: 在Struts 1中自定义请求处理器的示例:

<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"/>

This replaces the default Struts request processor with a Spring one, which matches mapped Struts actions with beans in the Spring context to perform dependency injection. 这将用Spring替换默认的Struts请求处理器,该处理器将映射的Struts操作与Spring上下文中的bean匹配以执行依赖项注入。

Example of delegating action handling in Struts 1: 在Struts 1中委派动作处理的示例:

<action-mappings>
    <action  path="/welcome" forward="/WEB-INF/pages/welcome.htm"/>
    <action  path="/searchEntry" forward="/WEB-INF/pages/search.jsp"/>
    <action  path="/searchSubmit" 
             type="org.springframework.web.struts.DelegatingActionProxy" 
             input="/searchEntry.do"
             validate="true"
             name="searchForm">
        <forward name="success" path="/WEB-INF/pages/detail.jsp"/>
        <forward name="failure" path="/WEB-INF/pages/search.jsp"/>
</action>  

Here the action type is replaced with a Spring proxy class, which looks up a matching bean (by path) in the Spring context. 在这里,动作类型被替换为Spring代理类,该类在Spring上下文中(通过路径)查找匹配的bean。 The purpose of this is also to inject dependencies in Struts 1 actions. 这样做的目的还在于在Struts 1动作中注入依赖项。 It is just another approach, giving more control to Spring. 这只是另一种方法,可以给Spring提供更多控制权。

I don't know how things work in Struts 2. 我不知道Struts 2中的工作原理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM