使用 DelegatingActionProxy 整合 sh(示例:项目 ssh_login)
1、在 web.xml 配置文件中配置 Listerner,用于加载 spring 的配置文件,示例代码如下:
a>、如果只有一个spring配置文件,刚可在web.xml中加载如下代码:
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
b>、如果有多个配置文件,则使用<context-param>元素来确定配置文件的文件名:
<context-param>
<!-- 参数名为contextConfigLocation -->
<param-name>contextConfigLocation</param-name>
<!-- 多个配置文件之间以,隔开 -->
<param-value>
/WEB-INF/daoContext.xml,/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- 采用listener创建ApplicationContext实例 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
2、在 struts-config.xml 文件中加载 spring 的配置文件:
<!-- 注册ContextLoaderPlugIn插件 -->
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml" />
</plug-in>
3 、 利 用 org.springframework.web.struts.DelegatingActionProxy :
DelegatinActionProxy 被 配 置 成 struts 的 action , 即 所 有 的 请 示 先 被
ActonServlet 拦截,然后将请示转发给对应的 action,而 action 的实现类全部是
DelegatingActionProxy,最后由 DelegatingActionProxy 将请示转发给 spring
的 bean。
示例代码:
<action path="/regedit" name="user" scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="login" path="/jsp/login.jsp"></forward>
<forward name="regedit" path="/jsp/regedit.jsp"></forward>
</action>
<!-- 定义初次访问时的路径 -->
<action path="/input"
评论0