ssh

Web.xml
Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?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的应用上下文  -->   
     <context-param>   
         <param-name>contextConfigLocation</param-name>   
         <param-value>classpath:applicationContext.xml</param-value>   
     </context-param>
     
     <listener>    
       <listener- class >    
          org.springframework.web.context.ContextLoaderListener             
       </listener- class >    
     </listener>  
     
     <!-- 刷新Introspector防止内存泄露 -->
     <listener>
         <listener- class >org.springframework.web.util.IntrospectorCleanupListener</listener- class >
     </listener>
 
     <!-- 设置字符编码 -->
     <filter>
         <filter-name>Set Character 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>
         <init-param>
             <param-name>forceEncoding</param-name>
             <!-- 强制进行转码 -->
             <param-value> true </param-value>
         </init-param>
     </filter>
     <filter-mapping>
         <filter-name>Set Character Encoding</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>
     
     
      
     <!-- session超时定义,单位为分钟 -->
     <session-config>
         <session-timeout> 30 </session-timeout>
     </session-config>
     
     
     <!-- 延长action中属性的生命周期, -->
     <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>
     
     <!-- Struts2 Filter -->
   <filter>
       <filter-name>struts</filter-name>
       <filter- class >
           org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
       </filter- class >
   </filter>
   <filter-mapping>
       <filter-name>struts</filter-name>
       <url-pattern>*.action</url-pattern>
   </filter-mapping>
   
 
   
   
   <welcome-file-list>
     <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
</web-app>


Application.xml

Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?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:context= "http://www.springframework.org/schema/context"
     xmlns:aop= "http://www.springframework.org/schema/aop"
     xmlns:tx= "http://www.springframework.org/schema/tx"
     xsi:schemaLocation="
             http: //www.springframework.org/schema/beans
             http: //www.springframework.org/schema/beans/spring-beans.xsd
             http: //www.springframework.org/schema/context
             http: //www.springframework.org/schema/context/spring-context.xsd
             http: //www.springframework.org/schema/aop
             http: //www.springframework.org/schema/aop/spring-aop.xsd
             http: //www.springframework.org/schema/tx
             http: //www.springframework.org/schema/tx/spring-tx.xsd"
             default -autowire= "byName" >
 
     <!-- 读取数据库配置 -->
     <bean id= "propertyConfigurer"  
           class = "org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >   
           <property name= "location" >   
              <value>classpath:db.properties</value>   
           </property>   
     </bean>
     
     <!-- DBCP数据库连接数据源的配置 -->       
     <bean id= "dataSource"  class = "org.apache.commons.dbcp.BasicDataSource"   destroy-method= "close" > <!-- 把连接重新放到连接池里 -->   
         <!-- 添加连接池属性 -->   
        <property name= "driverClassName"  value= "${db.driver}" />   
         <property name= "url"   value= "${db.url}" />   
         <property name= "username"  value= "${db.username}" />   
         <property name= "password"  value= "${db.password}" />   
         <property name= "initialSize"  value= "2"  /> <!-- 初始连接数 -->   
         <property name= "maxActive"  value= "50" /> <!-- 连接池最大连接数 -->   
         <property name= "maxIdle"  value= "20" />   <!-- 最大的可空闲的连接数 -->   
         <property name= "minIdle"  value= "10" />    <!-- 最小的可空闲的连接数 -->   
         <property name= "logAbandoned"  value= "true"  />  <!-- 超时后打印超时连接错误 -->   
         <property name= "removeAbandoned"  value= "true"  />   <!-- 超时移除连接 -->   
         <property name= "removeAbandonedTimeout"  value= "300" /> <!-- 超时时间 -->   
         <property name= "maxWait"  value= "1000" />   <!-- 最大可以等待时间 -->   
         <property name= "defaultAutoCommit"  value= "true" />  <!-- 自动提交, -->   
     </bean>   
        
     <!-- 将dataSource注入到下面的sessionFactory类里 -->   
     <bean id= "sessionFactory"  
         class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" >   
         <property name= "dataSource"  ref= "dataSource" /> 
           <property name= "hibernateProperties" > <!-- 这里是Properties列表 -->   
             <props>   
                 <prop key= "hibernate.dialect" >org.hibernate.dialect.SQLServerDialect</prop>   
                 <prop key= "hibernate.show_sql" > true </prop> <!-- 显示sql -->   
             </props>
         </property>   
     </bean>   
     
     <!-- 定义基于hibernate的事物管理器 -->
     <bean id= "txManager"  class = "org.springframework.orm.hibernate3.HibernateTransactionManager" >
       <property name= "sessionFactory"  ref= "sessionFactory" />
     </bean>
     
       <!-- 使用annotation定义事务 -->   
       <tx:annotation-driven transaction-manager= "txManager"  />
         
       <!-- 使用注解,在beans标签中添加context命名空间及其对应的schemaLocation -->
       <context:annotation-config/>
       <context:component-scan base- package = "net.xqx" />   
</beans>
Strtus.xml
Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?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>   
     <!-- 开启使用开发模式,详细错误提示 -->
     <constant name= "struts.devMode"  value= "false"  />
     <!-- 将对象交给spring管理 -->
     <constant name= "struts.objectFactory"  value= "spring"  />
     <!-- 指定资源编码类型 -->
     <constant name= "struts.i18n.encoding"  value= "UTF-8"  /> 
      <!-- 指定每次请求到达,重新加载资源文件 -->
     <constant name= "struts.i18n.reload"  value= "false"  />
     <!-- 指定每次配置文件更改后,自动重新加载 -->
     <constant name= "struts.configuration.xml.reload"  value= "true"  />
     <!-- 默认后缀名 -->
     <constant name= "struts.action.extension"  value= "do,action,jhtml,,"  />
     <!--  Struts Annotation --> 
       <constant name= "actionPackages"  value= "net.xqx"  />  
</struts>
BaseDao
Java code ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package  net.xqx.dao;
 
import  java.util.List;
 
import  org.hibernate.SessionFactory;
import  org.springframework.beans.factory.annotation.Autowired;
import  org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import  org.springframework.stereotype.Repository;
 
@Repository
public  class  BaseDao  extends  HibernateDaoSupport{
     
     @Autowired
      private  SessionFactory sessionFacotry;                
 
     public  List getUsers(){
         return  (List)sessionFacotry.getCurrentSession().createQuery( "from UserInfo" ).list();
     }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值