- 浏览: 1237756 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (193)
- ant/maven (6)
- algorithm (5)
- tomcat/weblogic/jboss (6)
- javascript/jquery (13)
- java (33)
- flex/flash (0)
- JPA/Hibernate/myBatis (18)
- java concurrent (7)
- test (2)
- windows/linux (6)
- java collection (7)
- design pattern (2)
- life/health (3)
- database (12)
- IDE (4)
- spring/ejb (20)
- html/css/ckeditor (7)
- jsp/servlet (3)
- java io (13)
- java security (4)
- jni (0)
- svn/git (2)
- english (2)
- java jmx (1)
- xml (1)
- struts/springmvc (9)
- middleware (2)
- cache (1)
- cglib (3)
最新评论
-
jlotusYo:
博主,真感谢。
Java 密码扩展无限制权限策略文件 -
senninha:
这个。。是api说明吧。。
ScheduledExecutorService 源码分析 -
zoutao2008:
请问大文件如何处理?按你这种方式的话,文件超过200M时就会报 ...
hessian系列之二:上传文件 -
lwj1113:
lwj1113 写道谢谢博主这么细致的demo;在系列五中通过 ...
myBatis系列之五:与Spring3集成 -
lwj1113:
谢谢博主这么细致的demo;在系列五中通过testng测试类跑 ...
myBatis系列之五:与Spring3集成
一. spring hibernate struts 整合开发(1) - 搭建环境
二. spring hibernate struts 整合开发(2) - Spring集成的Hibernate编码和测试
三. spring hibernate struts 整合开发(3) - Struts集成Spring
四. spring hibernate struts 整合开发(4) - Struts与Spring集成2
五. spring hibernate struts 整合开发(5) - Hibernate二级缓存
六. spring hibernate struts 整合开发(6) - 额外功能
Spring提供的CharacterEncoding和OpenSessionInView功能。
这里通过一个表单页面,提交数据,由struts封装数据,并由action调用业务层持久化数据,来引出乱码问题。
1. 创建index.jsp页面
2. 配置struts-config.xml
添加action和form-bean:
Note: 这里的action和form-bean都是用type来表示类的全限定名的,不是className。
3. 配置beans.xml
添加action bean:
4. 创建PersonForm和PersonDispatchAction类
5. 创建结果显示页面message.jsp
开启服务,打开index.jsp页面,输入名称,提交。
6. 使用spring解决struts1.3乱码问题
如果输入的名称是中文,保存到数据库后是乱码,可以使用spring提供的方法:
在web.xml加入:
7. 使用spring解决hibernate因session关闭导致的延迟加载例外问题
在web.xml加入:
整理自:传智播客spring教程
二. spring hibernate struts 整合开发(2) - Spring集成的Hibernate编码和测试
三. spring hibernate struts 整合开发(3) - Struts集成Spring
四. spring hibernate struts 整合开发(4) - Struts与Spring集成2
五. spring hibernate struts 整合开发(5) - Hibernate二级缓存
六. spring hibernate struts 整合开发(6) - 额外功能
Spring提供的CharacterEncoding和OpenSessionInView功能。
这里通过一个表单页面,提交数据,由struts封装数据,并由action调用业务层持久化数据,来引出乱码问题。
1. 创建index.jsp页面
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%> <html:form action="/person/dispose"> <html:text property="name" /> <html:hidden property="method" value="add" /> <html:submit value="Submit" /> </html:form>
2. 配置struts-config.xml
添加action和form-bean:
<form-beans> <form-bean name="personForm" type="com.john.web.formbean.PersonForm" /> </form-beans> <action-mappings> <!-- Let the action be managed by spring, thus type property is eliminated --> <action path="/person/dispose" name="personForm" scope="request" parameter="method" validate="false"> <forward name="message" path="/WEB-INF/pages/message.jsp"/> </action> </action-mappings>
Note: 这里的action和form-bean都是用type来表示类的全限定名的,不是className。
3. 配置beans.xml
添加action bean:
<bean name="/person/dispose" class="com.john.web.action.PersonDisposeAction"/>
4. 创建PersonForm和PersonDispatchAction类
public class PersonForm extends ActionForm { private Integer id; private String name; // getters and setters are omitted }
// Utilize DispatchAction to execute specified method public class PersonDisposeAction extends DispatchAction{ // Since this action is managed by spring, we could // inject the business bean @Resource PersonService personService; public ActionForward add(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { PersonForm personForm = (PersonForm)form; personService.save(new Person(personForm.getName())); request.setAttribute("result", "Saved successfully!"); return mapping.findForward("message"); } }
5. 创建结果显示页面message.jsp
<body> ${result} </body>
开启服务,打开index.jsp页面,输入名称,提交。
6. 使用spring解决struts1.3乱码问题
如果输入的名称是中文,保存到数据库后是乱码,可以使用spring提供的方法:
在web.xml加入:
<filter> <filter-name>encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
7. 使用spring解决hibernate因session关闭导致的延迟加载例外问题
在web.xml加入:
<filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> <filter-mapping> <filter-name>OpenSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
整理自:传智播客spring教程
发表评论
-
本地事务系列之五:使用Transactional注解
2014-08-02 18:16 2780AOP的配置稍显复杂,通过@Transactional注解,同 ... -
本地事务系列之四:使用AOP
2014-08-02 17:08 863Spring AOP通过在文件中配置来管理事务,好处是对代码侵 ... -
本地事务系列之三:使用TransactionTemplate
2014-07-17 22:15 6690TransactionTemplate的灵活性好,可以给代码块 ... -
本地事务系列之二:使用PlatformTransactionManager
2014-07-17 21:37 5334Spring的事务管理器接口: public interf ... -
本地事务系列之一:JDBC操作
2014-07-08 23:04 1206本地事务即对一个数据源进行操作。大多数数据库支持事务。 先看 ... -
Spring AOP 源码系列:ProxyFactoryBean
2014-04-21 18:01 0public class ProxyFactoryBean ... -
Spring AOP 源码系列
2014-04-21 09:22 0Spring AOP通过JDK的正则表达式对Pointcut表 ... -
Spring AOP系列之五:后置通知
2014-04-14 08:59 1633和前置通知类似, 通过实现org.springframewor ... -
Spring AOP系列之四:前置通知
2014-04-13 21:28 1789通过实现org.springframework.aop.M ... -
Spring AOP系列之三:环绕代理
2014-04-13 18:20 1382通过实现org.aopalliance.intercept.M ... -
Spring AOP系列之二:Java代理
2014-04-13 18:00 1017通过Java代理的方式: 汽车的代理,需要实现java.la ... -
Spring AOP系列之一:手动方式
2014-04-13 17:44 1352AOP (Aspect Oriented Progra ... -
HibernateTemplate 使用
2014-03-03 22:09 01. queryListBySql hibernateTe ... -
Spring的组件扫描
2017-09-16 21:58 1024Spring2.0以后的版本中,引入了基于注解(Annotat ... -
ContextLoaderListener和ContextCleanupListener源码分析
2013-12-18 15:55 0public class ContextLoaderLis ... -
Cglib2AopProxy 源码分析
2013-12-05 14:30 0final class Cglib2AopProxy im ... -
Spring生命周期方法的调用顺序
2013-11-19 22:04 0Spring的几个接口: BeanFactoryAware: ... -
一、Spring AOP的简单实例
2013-11-06 23:31 17311. 往pom.xml文件添加以下依赖: <depe ... -
Spring配置中的bean引用其它bean的属性值
2013-01-23 15:24 4178这项功能在spring的3.0版本以上才支持,如果使用较早的版 ... -
spring JPA struts 整合开发(2) - spring集成struts
2012-05-20 20:55 1387一. spring JPA struts 整合开发(1) - ...
相关推荐
最近温习ssh2整合编程,顺便浏览下struts2有什么更新的消息,下载了新版本的struts2的2.1.8.1版,使用的是MyEclipse8.0开发,但是问题就随之而来了。MyEclipse8.0中自带的struts2版本是2.1.6,spring版本有2.0,2.5...
资源中包含ssh整合的基础java包可以进行基础开发,如果需要额外的功能,则需加入对应依赖的包。数据库的链接包是MySQl数据库,链接使用的C3P0 SSH是 struts+spring+hibernate的一个集成框架,是目前比较流行的一种...
SSH三大框架整合开发的基础JAR包!共31个jar文件,基本的开发足够啦!高级开发需额外添加jar包! Struts2的版本:2.3.15 Spring的版本:3.1.1 Hibernate的版本:3.3.2
14.2.3. 帮助简化开发的额外的标签 14.3. Tiles 14.3.1. 需要的资源 14.3.2. 如何集成Tiles 14.3.2.1. InternalResourceViewResolver 14.3.2.2. ResourceBundleViewResolver 14.4. Velocity和FreeMarker 14.4.1. ...
14.2.3. 帮助简化开发的额外的标签 14.3. Tiles 14.3.1. 需要的资源 14.3.2. 如何集成Tiles 14.4. Velocity和FreeMarker 14.4.1. 需要的资源 14.4.2. Context 配置 14.4.3. 创建模板 14.4.4. 高级配置 ...
第一个 Struts 程式 在 Struts 中整合 Spring 第一个 JSF 程式 在 JSF 中整合 Spring <br> 其它 Spring 提供了简化且一致的方式,让您在使用一些 API 或服务时更加简单。 远程...
Spring Framework 开发参考手册 Rod Johnson Juergen Hoeller Alef Arendsen Colin Sampaleanu Rob Harrop Thomas Risberg Darren Davison Dmitriy Kopylenko Mark Pollack Thierry Templier Erwin ...
14.2.3. 帮助简化开发的额外的标签 14.3. Tiles 14.3.1. 需要的资源 14.3.2. 如何集成Tiles 14.4. Velocity和FreeMarker 14.4.1. 需要的资源 14.4.2. Context 配置 14.4.3. 创建模板 14.4.4. 高级配置 ...
14.2.3. 帮助简化开发的额外的标签 14.3. Tiles 14.3.1. 需要的资源 14.3.2. 如何集成Tiles 14.4. Velocity和FreeMarker 14.4.1. 需要的资源 14.4.2. Context 配置 14.4.3. 创建模板 14.4.4. 高级配置 ...
MyEclipse目前支持Java Servlet,AJAX, JSP, JSF, Struts,Spring, Hibernate,EJB3,JDBC数据库链接工具等多项功能。可以说MyEclipse几乎囊括了目前所有主流开源产品的专属eclipse开发工具。因此在开发本系统时我把它...