WEB框架研究笔记七(Spring2+struts2)

Spring2 Web研究失败之后,只能走Spring+Struts结合的路线。

STRUTS的例子前面已经写过了。现在的问题是STRUTS怎么用上SPRING。

也就是说,原来在配置STRUTS.XML的时候,写ACTION是直接写ACTION所在的JAVA类名,现在这块交给SPRING来管理,这样就可以为这个类注入其他内容。

修改方法:

1.拷贝Struts.properties到src目录(和struts.XML同一个目录)
struts.objectFactory = spring 
struts.locale=zh_CN
struts.i18n.encoding = GBK
2.拷贝spring.jar,struts2-spring-plugin-x.jar
3.配置WEB.XML
   <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/configs/applicationcontext.xml</param-value>
  </context-param>
      <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>
4.配置string用的applicationcontext,增加action连接项
    <bean id="GridAction" class="action.GridAction" singleton="false">
    </bean>  
5.修改struts.xml
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />
    <constant name="struts.i18n.encoding" value="GBK" />  

    <action name="grid" class="action.GridAction">
    </action>

注意几个地方:

1.Struts.property 文件直接放到和struts.xml同一个目录就可以了

2.需要拷贝struts2-spring-plugin-x.jar,注意版本,由于我刚开始拷贝的版本不对,一直用不起来,找了很长时间原因。

3.struts.xml中设置

<constant name="struts.devMode" value="false" />
,网上给的例子都是TRUE的,导致会报一个错,后来改成FALSE就好了,什么原因不知道。

--------------------------

OK,接下去就是如何结合hibernate的问题了,这个应该比较简单的。

原文地址:https://www.cnblogs.com/barryhong/p/1519064.html