shh整合后web.xml、spring配置文件和struts.xml的内容
1:web.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.5"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
- <!-- 指定spring的配置文件,默认从web根目录寻找配置文件,我们可以通过spring 提供的classpath:前缀指定从类路径下寻找-->
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:beans.xml</param-value>
- </context-param>
- <!-- 对Spring容器进行实例化 -->
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <!-- 启动struts2框架 -->
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
2:spring配置文件:
- <?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-2.5.xsd
- http://www.springframework.org/schema/tx
- http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
- <!-- 通过注解的方式将类交给spring管理 -->
- <!-- 是被@Component、@Service、@Controller、@Repository注解的类,都可以纳入spring容器的管理中 -->
- <context:component-scan base-package="cn.itcast"/>
- <!-- 配置文件占位符 -->
- <!--<context:property-placeholder location="classpath:jdbc.properties"/>-->
- <!-- 配置数据源 -->
- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
- <property name="driverClass" value="com.mysql.jdbc.Driver"/>
- <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/itcast?useUnicode=true&characterEncoding=UTF-8"/>
- <property name="user" value="root"/>
- <property name="password" value="123"/>
- <!-- 连接池启动时的初始值 -->
- <property name="initialPoolSize" value="1"/>
- <!-- 连接池中保留的最小连接数 -->
- <property name="minPoolSize" value="1"/>
- <!-- 连接池中保留的最大连接数 -->
- <property name="maxPoolSize" value="15"/>
- <!-- 最大空闲时间 ,60秒内未使用则丢弃。若为0则永不丢弃。Default:0-->
- <property name="maxIdleTime" value="60"/>
- <!-- 当连接池中的连接耗尽的时候c3p0一次同时获取的连接数,default:3 -->
- <property name="acquireIncrement" value="5"/>
- <!-- 每60秒检查所有连接池中的空闲连接。Default:0 -->
- <property name="idleConnectionTestPeriod" value="60"/>
- </bean>
- <!-- 用spring创建sessionFactory供hibernate用 -->
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="mappingResources">
- <list>
- <value>cn/itcast/bean/Employee.hbm.xml</value>
- </list>
- </property>
- <property name="hibernateProperties">
- <value>
- hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
- hibernate.hbm2ddl.auto=update
- hibernate.show_sql=true
- hibernate.format_sql=false
- </value>
- </property>
- </bean>
- <!--
- hibernate.cache.use_second_level_cache=true
- hibernate.cache.use_query_cache=false
- hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
- -->
- <!-- 用spring创建sessionFactory供hibernate用 -->
- <!-- 基于注解的映射文件-->
- <!--
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="annotatedClasses">
- <list>
- <value>cn.itcast.bean.Employee</value>
- </list>
- </property>
- <property name="hibernateProperties">
- <value>
- hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
- hibernate.hbm2ddl.auto=update
- hibernate.show_sql=true
- hibernate.format_sql=false
- </value>
- </property>
- </bean>
- -->
- <!-- 用spring创建sessionFactory供hibernate用 -->
- <!-- 基于注解的映射文件-->
- <!--
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
- <property name="dataSource" ref="dataSource" />
- <property name="packagesToScan" value="com.sdcncsi.entity.*" />
- <property name="hibernateProperties">
- <value>
- hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
- hibernate.hbm2ddl.auto=update
- hibernate.show_sql=true
- hibernate.format_sql=false
- </value>
- </property>
- </bean>
- -->
- <!-- 事务管理服务 -->
- <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory" ref="sessionFactory"/>
- </bean>
- <!-- 采用@Transaction注解方式使用事务 -->
- <tx:annotation-driven transaction-manager="txManager"/>
- </beans>
ps:当使用注解的方式关于映射,则就不是写映射文件了;
而在bean中用注解,下面举个例子:
- @SuppressWarnings("serial")
- @Entity()
- @Table(name="zft_check_login")
- @Cache(usage = CacheConcurrencyStrategy.NONE)
- public class CheckloginEntity implements Serializable{
- private Long id;
- private Long staff_id;
- private Date latest_time;
- private Staff staff;
- private Set<Equipment> equipments;
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- public Long getId() {
- return id;
- }
- public void setId(Long id) {
- this.id = id;
- }
- public Long getStaff_id() {
- return staff_id;
- }
- public void setStaff_id(Long staff_id) {
- this.staff_id = staff_id;
- }
- public Date getLatest_time() {
- return latest_time;
- }
- public void setLatest_time(Date latest_time) {
- this.latest_time = latest_time;
- }
- @OneToOne(cascade = {CascadeType.PERSIST,CascadeType.MERGE},fetch = FetchType.LAZY)
- @JoinColumn(name = "staff_id",insertable=false,updatable=false)
- public Staff getStaff() {
- return staff;
- }
- public void setStaff(Staff staff) {
- this.staff = staff;
- }
- @OneToMany(fetch = FetchType.LAZY)
- @JoinColumn(name = "staff_id",referencedColumnName="staff_id",insertable=false,updatable=false)
- public Set<Equipment> getEquipments() {
- return equipments;
- }
- public void setEquipments(Set<Equipment> equipments) {
- this.equipments = equipments;
- }
- @Transient
- public String getPhoneNums() throws Exception{
- return ReflectionUtils.fetchElementPropertyToString(equipments,"equipmentPhone",", ");
- }
- @Transient
- public Long getMinutes() throws Exception{
- Date etime=new Date(System.currentTimeMillis());
- return (etime.getTime() - this.getLatest_time().getTime())/(60*1000);
- }
- }
3: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>
- <!-- 更换掉struts2内部的对象创建工厂,action用spring创建 -->
- <constant name="struts.objectFactory" value="spring"/>
- <!-- 将struts的主题改成默认主题,防止其生成不必要的html代码 -->
- <constant name="struts.ui.theme" value="simple"/>
- <package name="employee" namespace="/employee" extends="struts-default">
- <!-- 因为action有spring创建,所以只需指定spring创建的action的对象的名称就行 -->
- <action name="list" class="employeeAction">
- <result name="list">/WEB-INF/page/employee.jsp</result>
- </action>
- <action name="manage_*" class="employeeManageAction" method="{1}">
- <result name="add">/WEB-INF/page/employeeAdd.jsp</result>
- <result name="message">/WEB-INF/page/message.jsp</result>
- </action>
- </package>
- </struts>
shh整合后web.xml、spring配置文件和struts.xml的内容的更多相关文章
- 一 SSH整合:Spring整合Struts2的两种方式,struts.xml管理Action&Bean管理Action
SSH回顾 1 引入jar包 Struts2的jar包 D:\Struts2\struts-2.3.35\apps\struts2-blank\WEB-INF\lib 开发基本包 Struts2有一 ...
- maven创建web工程Spring配置文件找不到问题解决方案
使用maven创建web工程,将Spring配置文件applicationContext.xml放在src/resource下,用eclipse编译时提示class path resource [ap ...
- Spring Web项目spring配置文件随服务器启动时自动加载
前言:其实配置文件不随服务器启动时加载也是可以的,但是这样操作的话,每次获取相应对象,就会去读取一次配置文件,从而降低程序的效率,而Spring中已经为我们提供了监听器,可监听服务器是否启动,然后在启 ...
- maven创建web工程Spring配置文件找不到
使用maven创建web工程,将Spring配置文件applicationContext.xml放在src/resource下,用eclipse编译时提示class path resource [ap ...
- struts2与struts1整合,Unable to load configuration. - interceptor-ref ... struts.xml
struts.xml中为了与struts1的MVC模式整合,需要类似如下的拦截器的引用 <interceptor-stack name="integration"> & ...
- struts2中struts.xml配置文件详解【未整理】
1. 深入Struts2的配置文件 本部分主要介绍struts.xml的常用配置. 1.1. 包配置: Struts2框架中核心组件就是Action.拦截器等,Struts2框架使用包来管 ...
- Struts2笔记1:--Struts2原理、优点、编程流程、6大配置文件以及核心配置文件struts.xml
Struts2原理(底层使用的是Servlet的doFilter方法): Struts2优点: 第一个Struts程序: 在开发Struts程序之前,首先要导入额外的jar包,基本需求的是14个jar ...
- 关于spring配置文件的头部编写
//普通spring配置文件模板1 <?xml version="1.0" encoding="UTF-8" ?> <beans xmlns: ...
- Spring配置文件的读取
1.配置文件的命名 Spring框架中的默认配置文件,建议命名为applicationContext.xml * 编写配置文件,默认位置有两个 ①src目录.②WEB-INF目录 2.Spring 配 ...
随机推荐
- FTP 服务器性能 测试点
测试FTP 服务器性能测试点: 1. ftp软件性能 2. ftp服务器硬件处理性能(IO/CPU/ROM) 3. ftp服务器网络吞吐性能 (NET IO) 有针对性的测试 达到的效果会比较好. 建 ...
- ReadyBoost
ReadyBoost是Windows Vista中的新技术,在继Windows Vista的下一代操作系统Windows 7中,同样包含了这项技术,它利用了闪存随机读写及零碎文档读写上的优势来提高计算 ...
- linux中的信号简介和trap命令
1.信号 linux通过信号来在运行在系统上的进程之间通信,也可以通过信号来控制shell脚本的运行 主要有一下信号 1 ##进程重新加载配置 2 ##删除进程在内存中的数据 3 ##删除鼠标在内存中 ...
- 20145235李涛《网络对抗》Exp9 Web安全基础实践
基础问答 SQL注入攻击原理,如何防御? SQL注入攻击就是通过把SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意SQL命令的目的. 对于SQL注入攻击的防范 ...
- autofac.webapi2
quick start https://autofaccn.readthedocs.io/en/latest/integration/webapi.html#quick-start To get Au ...
- spark 参数调优
调整partition数量,每次reduece和distict的时候都应该调整,数量太大和太小都不好,通常来讲保证一个partition的大小在1-2G左右为宜 调整excutors 调整core 调 ...
- 全卷积网络(FCN)与图像分割
最近在做物体检测,也用到了全卷积网络,来此学习一波. 这篇文章写了很好,有利于入门,在此记录一下: http://blog.csdn.net/taigw/article/details/5140144 ...
- tp添加分页
//分页开始 $count=M('article')->where($condition)->count(); $p = intval($p) > 0 ? $p : 1; $page ...
- quartz(8)--其他
JOB并发执行 Quartz定时任务默认都是并发执行的,不会等待上一次任务执行完毕,只要间隔时间到就会执行, 如果定时任执行太长,会长时间占用资源,导致其它任务堵塞. 设置为非并发 1)Job类加上注 ...
- 解决hive交互模式退格键乱码
在hive的交互模式下,输入退格.方向键等,出现乱码,可以通过如下方法解决: 1.修改bashrc文件: vi ~/.bashrc 在文件最后添加一行: stty erase ^H. 2.使修改生效: ...