采用
DelegatingRequestProcessor
将处理转发给Spring容器中的bean (比如:struts action)
DelegatingRequestProcessor 继承自RequestProcessor。为了让 Struts 使用 DelegatingRequestProcessor ,还需要在 struts -config.xml文件中增加如下代码:
<controller processorClass=" org . springframework . web . struts . DelegatingRequestProcessor " />
这一行代码是告诉 Struts 用 DelegatingRequestProcessor 来代替原来的RequestProcessor。完成设置这个设置后, Struts 会将拦截到的用户请求转发到Spring context下的bean,根据bean的name属性来匹配。而 Struts 中的action配置则无需配置type属性(即使配置了type属性也不起任何作用, 除非在spring的配置文件里找不到对应的name属性值 ,除非这个条件直到今天才知道。记下来备忘:))。
配置了上面的一行代码后,就可以在Spring的配置文件(可以不是applicationContext.xml,比如假设这里是action-servlet.xml)中配置用来处理请求的Action bean了。配置的时候需要注意的是Action bean不再需要id属性,而要用name替代id属性,这时name属性的值应与 struts -config.xml中配置的Action的path属性的值相同。
这样,处理请求的Action就能处于Spring的管理之下了。
DelegatingRequestProcessor 继承自RequestProcessor。为了让 Struts 使用 DelegatingRequestProcessor ,还需要在 struts -config.xml文件中增加如下代码:
<controller processorClass=" org . springframework . web . struts . DelegatingRequestProcessor " />
这一行代码是告诉 Struts 用 DelegatingRequestProcessor 来代替原来的RequestProcessor。完成设置这个设置后, Struts 会将拦截到的用户请求转发到Spring context下的bean,根据bean的name属性来匹配。而 Struts 中的action配置则无需配置type属性(即使配置了type属性也不起任何作用, 除非在spring的配置文件里找不到对应的name属性值 ,除非这个条件直到今天才知道。记下来备忘:))。
配置了上面的一行代码后,就可以在Spring的配置文件(可以不是applicationContext.xml,比如假设这里是action-servlet.xml)中配置用来处理请求的Action bean了。配置的时候需要注意的是Action bean不再需要id属性,而要用name替代id属性,这时name属性的值应与 struts -config.xml中配置的Action的path属性的值相同。
这样,处理请求的Action就能处于Spring的管理之下了。