您好,欢迎访问一九零五行业门户网

S2SH开发小程序的图文代码分享

1.       源码准备:
1)  struts2 源码:
a)       struts-2.1.6-all.zip
b)      xwork-2.1.6.rar
c)      jp.gr.java_conf.ussiy.app.propedit_5.3.3.zip,eclipse 管理资源文件
2)  spring2.5 源码:
a) spring-framework-2.5.6.zip
3)  hibernate3.2 源码:
a)       hibernate-distribution-3.3.2.ga-dist.zip
b)      hibernate-annotations-3.4.0.ga.zip
c)      slf4j-1.5.8.zip
2.       ssh 所需要的 jar 包:
1)  jar 包图解:
2)  jar 包相关说明:
3.       所需注意的问题:
1)  @scope(value=”propotype”) 问题
a)       每定义的 action 类,需要定义其类型为: propotype ,在类上面加上:@scope(value=”propotype”)
b)      如果不设置, spring 初始化的每个类,默认 scope 值为 singleton 方式。然而 webwork 的action 不是线程安全的,要求在多线程环境下必须是一个线程对应一个独立的实例,不能使用singleton 。所以,我们在 spring 配置 webwork action bean 时,需要加上属性scope=”prototype” 或 singleton=”false” 。
2)  opensessioninviewfilter 相关问题:
a)       由于 hibernate 引入了 lazy load 特性 () ,使得脱离 hibernate 的 session 周期的对象如果再想通过 getter/load 方法取到其关联对象的值, hibernate 会抛出一个 lazyload 的exception 。
b)      解决这个问题, spring 引入了这个 filter ,使得 hibernate 的 session 的生命周期变长。
c)      具体配置:
<filter> <filter-name>opensessioninview</filter-name> <filter-class> org.springframework.orm.hibernate3.support.opensessioninviewfilter </filter-class> <init-param> <param-name>sessionfactorybeanname</param-name> <param-value>sf</param-value> </init-param> </filter> <filter-mapping> <filter-name>opensessioninview</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
3) 中文乱码问题:
a) 中文乱码问题,在 struts.xml 中配置:
<constant name="struts.i18n.encoding" value="gb18030" />
仍然无法解决。
b) 此为 strtust2.1.6 的一个 bug 问题,解决方法是使用 spring 提供 encodingfilter实现。
c) encodingfilter 具体配置:
<filter> <filter-name>encodingfilter</filter-name> <filter-class>org.springframework.web.filter.characterencodingfilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>gbk</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingfilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>&nbsp;
4) filter 在web.xml 中的顺序问题:
a) 在web.xml 配置中功能越大的filter 应该越配在前面。
b) 多个filter 在过滤过程图解:
如下:
5)上传文件时清除缓存filter:
<filter> <filter-name>struts-cleanup</filter-name> <filter-class>org.apache.struts2.dispatcher.actioncontextcleanup</filter-class> </filter> <filter-mapping> <filter-name>struts-cleanup</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
在做上传文件的时候,要在web.xml中增加actioncontextcleanup这个filter,如果不增加,会发生第一次上传取不到文件的情况
以上就是s2sh开发小程序的图文代码分享的详细内容。
其它类似信息

推荐信息