首页 微信小程序 小程序开发 S2SH开发小程序的图文代码分享

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

Apr 15, 2017 am 11:17 AM

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 包图解:

1472.jpg

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> 
登录后复制

4) filter 在web.xml 中的顺序问题:

a) 在web.xml 配置中功能越大的filter 应该越配在前面。

b) 多个filter 在过滤过程图解:

    如下:

1473.jpg

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开发小程序的图文代码分享的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)