spring+hibernate+struts整合(2)
spring和struts2的整合
1:配置Web.xml文件
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
2:配置struts.xml文件。
在源码根目录下新建一个struts.xml文件。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-- 指定Web应用的默认编码集,相当于调用HttpServletRequest的setCharacterEncoding方法 -->
<!-- <constant name="struts.i18n.encoding" value="UTF-8"/>-->
<!-- -->
<!-- -->
<!-- 该属性指定需要Struts 2处理的请求后缀,该属性的默认值是action,即所有匹配*.action的请求都由Struts2处理。-->
<!-- 如果用户需要指定多个请求后缀,则多个后缀之间以英文逗号(,)隔开。 -->
<!-- <constant name="struts.action.extension" value="do"/>-->
<!-- 设置浏览器是否缓存静态内容,默认值为true(生产环境下使用),开发阶段最好关闭 -->
<!-- <constant name="struts.serve.static.browserCache" value="false"/>-->
<!-- 当struts的配置文件修改后,系统是否自动重新加载该文件,默认值为false(生产环境下使用),开发阶段最好打开 -->
<!-- <constant name="struts.configuration.xml.reload" value="true"/>-->
<!-- 开发模式下使用,这样可以打印出更详细的错误信息 -->
<!-- <constant name="struts.devMode" value="false" />-->
<!-- 默认的视图主题 -->
<!-- <constant name="struts.ui.theme" value="simple" />--> <constant name="struts.objectFactory" value="spring" /> <package name="user" namespace="/user" extends="struts-default">
<action name="userlist" class="userAction" method="userList">
<result name="list">/WEB-INF/user/userList.jsp</result>
</action>
</package>
</struts>
需要说明的是上述文件中的class中的userAction是需要在bean.xml中配置的,正式由于我之前没有配,导致了一个让我纠结了几天的问题。
3:配置bean.xml文件
我的理解是这样的,如果你想把某个东西交给spring管理,就必须要在bean.xml中配置。这样spring才能够识别。
<!-- 注册Action -->
<bean id="userAction" class="com.test.action.UserAction" scope="prototype"/> <!-- 注册 Interface-->
<bean id="userService" class="com.test.implement.userServiceBean"/>
4:编写action
@Controller
public class UserAction { @Resource private userService userservice; public String userList()
{
ActionContext.getContext().put("users", userservice.getAll());
return "list";
}
//
public String execute()
{
return "list";
}
}
因为这里,我将UserAction 和userService 交给spring 管理了,所以在上面的bean.xml中我需要配置。
到这里,spring和struts的整合基本完成。
spring+hibernate+struts整合(2)的更多相关文章
- spring+hibernate+struts整合(1)
spring+hibernate:整合 步骤1:引入类包 如下图:这里是所有的类包,为后面的struts整合考虑
- jbpm与spring hibernate struts整合
applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xm ...
- Spring+Hibernate+Struts(SSH)框架整合
SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...
- Struts+Spring+Hibernate项目整合AJAX+JSON
1.什么是AJAX AJAX是 "Asynchronous JavaScript and XML" 的简称,即异步的JavaScript和XML. 所谓异步,就是提交一个请求不必等 ...
- Spring与Struts整合
Spring框架是一个非常优秀的轻量级Java EE容器,Spring框架是整个轻量级Java EE框架的核心.大部分的Java EE应用,都会考虑使用Spring容器管理应用中的组件,从而保证各组件 ...
- spring 和 struts 整合遇到的问题(学习中)
一大早就报错 org.hibernate.TransactionException: Transaction not successfully started at org.hibernate.eng ...
- spring和struts整合
整合准备:导入jar包 如果只是访问action,没有做数据库方面的操作的话 只需要导入下面的jar spring相关jar 以及struts相关jar包 整合过程: 用到了struts所以需要在we ...
- Spring,hibernate,struts的面试笔试题(含答案)
Hibernate工作原理及为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Sesssion 4.创建事务Transation 5.持久 ...
- Struts2 Spring Hibernate 框架整合 Annotation MavenProject
项目结构目录 pom.xml 添加和管理jar包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...
随机推荐
- http和数据库sql分析与窃听技术
用tunnel,tunnel是一种技术称谓,将其放到真正的服务器和客户端之间.调试阶段可以使用webcream运行tomcat作为模拟的真正的服务器. 具体:用apache axis及其项目中的工具t ...
- Shell字符串使用十进制转换
其实不知道该起什么题目. 先说下需求,线上的log是按照五分钟为粒度切分的,即每五分钟产生一个文件,19:04的log写入到 1900结尾的log文件中,19:05写入到1905结尾的log文件中. ...
- Linux下的scp拷贝命令详解
相同Linux系统中对文件复制拷贝可以用CP命令: cp [options] source dest cp [options] source... directory 说明:将一个档案拷贝至另一档案, ...
- hadoop conf中xml文件修改
core-site.xml <?xml version="1.0"?><?xml-stylesheet type="text/xsl" hre ...
- POJ 2387 Til the Cows Come Home (最短路 dijkstra)
Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...
- MAT(2)安装Memory Analyzer
http://www.eclipse.org/mat/ 两大功能: 1.find memory leaks 2.reduce memory consumption 安装步骤: 1. 打开 eclips ...
- ACID CAP BASE介绍
ACID ACID,是指数据库管理系统(DBMS)在写入/更新资料的过程中,为保证事务(transaction)是正确可靠的,所必须具备的四个特性:原子性(atomicity,或称不可分割性).一致性 ...
- Unity3D行为树插件Behave学习笔记
Behave1.4行为树插件 下载地址:http://pan.baidu.com/s/1i4uuX0L 安装插件和使用 我们先来看看插件的安装和基本使用方法,新建一个Unity3D项目,这里我使用的是 ...
- Castle IOC容器实践之FactorySupport Facility
PDF版本下载:http://file.ddvip.com/2008_10/1223538519_ddvip_4853.rar示例代码下载:http://file.ddvip.com/2008_10/ ...
- 开源的读取Excel文件组件-ExcelDataReader
ExcelDataReader可以读取 Microsoft Excel 文件 ('97-2007),支持Windows .Net Framework 2 +. Windows Mobile with ...