zoukankan      html  css  js  c++  java
  • 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的问题了,这个应该比较简单的。

  • 相关阅读:
    svn checkout单个文件
    ubuntu下使用fstab挂载硬盘时,属于root,如何把它改为属于一个用户的(如sgjm)
    TCP/IP 端口号大全
    Netstat命令详解(windows下)
    Linux netstat命令详解
    windows下用cmd命令netstat查看系统端口使用情况
    LR函数基础(一)(二)
    loadrunner error 27796 Failed to connect to server
    安装lr时无法将值Disable Script Debugger 写入注册表
    LR接口性能测试提示Code
  • 原文地址:https://www.cnblogs.com/barryhong/p/1519064.html
Copyright © 2011-2022 走看看