`
sgl124764903
  • 浏览: 174658 次
  • 性别: Icon_minigender_1
  • 来自: 邯郸
社区版块
存档分类
最新评论

Struts2+spring2+hibernate3整合方案(2)

    博客分类:
  • SSH2
阅读更多

applicationContext-dao.xml内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- 根DAO -->
<bean id="genericDao" class="com.firstssh.common.dao.GenericDao">
    
<property name="sessionFactory">
        
<ref bean="sessionFactory" />
    
</property>
</bean>
<bean id="userDao" class="com.firstssh.dao.impl.UserDao" parent="genericDao" />
</beans>


applicationContext-service.xml内容:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="userService" class="com.firstssh.service.impl.UserService">
    
<property name="userDao">
        
<ref bean="userDao"/>
    
</property>
</bean>
<bean id="validateName" class="com.firstssh.common.Bean.ValidateName">
    
<property name="userService">
        
<ref local="userService"/>
    
</property>
</bean>
</beans>


action-servlet.xml内容:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>

    
<bean id="LoginAction" class="com.firstssh.action.LoginAction"
        scope
="prototype">
        
<property name="userService" ref="userService" />
    
</bean>
    
<bean id="RegistAction" class="com.firstssh.action.RegistAction"
        scope
="prototype">
        
<property name="userService" ref="userService" />
    
</bean>
</beans>


以上几个xml文件的内容暂且不要理会,继续往下看,你就自动明白的,不用我解释。
4)日志部分:log4j.properties 、commons-logging.properties
log4j.properties内容:

 

# For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml!
# For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.
log4j.rootLogger
=INFO, stdout,
 logfile

log4j.appender.stdout
=
org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout
=
org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern
=%d %p [%c]
 - %m%n

log4j.appender.logfile
=
org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File
=
${firstssh.root}/WEB-INF/logs/firstssh.log
log4j.appender.logfile.MaxFileSize
=
512KB
# Keep three backup files.
log4j.appender.logfile.MaxBackupIndex
=3

# Pattern to output: date priority 
[category] - message
log4j.appender.logfile.layout
=
org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern
=%d %p [%c]
 - %m%n
# OpenSymphony Stuff
log4j.logger.com.opensymphony
=
INFO
log4j.logger.org.apache.struts2
=
INFO
# Spring Stuff
log4j.logger.org.springframework
=
INFO
# Hibernate Stuff
log4j.logger.org.hiberante
=INFO

commons-logging.properties
内容:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger


5)web.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" 
 xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
 
 xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
 
 version
="2.4">

 
<display-name>firstssh</display-name>
 
<description>this is a simple example</description>
 
<context-param>
  
<param-name>webAppRootKey</param-name>
  
<param-value>firstssh.root</param-value>
 
</context-param>
 
 
<context-param>
  
<param-name>contextConfigLocation</param-name>
  
<param-value>/WEB-INF/applicationContext-*.xml,/WEB-INF/action-servlet.xml</param-value>
 
</context-param>
 
<context-param>
  
<param-name>log4jConfigLocation</param-name>
  
<param-value>/WEB-INF/log4j.properties</param-value>
 
</context-param>
 
<listener>
  
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 
</listener>
 
<!-- 用于初始化Spring容器的Listener -->
    
<listener>
        
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    
</listener>
 
 
 
<!-- 定义整合SiteMesh必须的ActionContextCleanUp Filter 
 <filter>
  <filter-name>struts-cleanup</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
 </filter>
-->

 
<!-- 定义Struts2的FilterDispathcer的Filter -->
    
<filter>
        
<filter-name>struts2</filter-name>
        
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    
</filter>

   
<!--   <filter-mapping>
        <filter-name>struts-cleanup</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
-->

 
<!-- FilterDispatcher用来初始化struts2并且处理所有的WEB请求。 -->
    
<filter-mapping>
        
<filter-name>struts2</filter-name>
        
<url-pattern>/*</url-pattern>
    
</filter-mapping>
    
   
<!-- 这是一个产生验证码的servlet -->
    
<servlet>
        
<servlet-name>img</servlet-name>
        
<servlet-class>com.firstssh.servlet.AuthImg</servlet-class>
    
</servlet>
  
    
<servlet-mapping>
        
<servlet-name>img</servlet-name>
     
<url-pattern>/authImg</url-pattern>
    
</servlet-mapping>
    
<filter>   
        
<filter-name>encodingFilter</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>encodingFilter</filter-name>
   
        
<url-pattern>*.action</url-pattern>
   
    
</filter-mapping>
   
    
<filter-mapping>
   
        
<filter-name>encodingFilter</filter-name>
   
        
<url-pattern>*.jsp</url-pattern>
   
    
</filter-mapping>

    
<filter>   
        
<filter-name>hibernateFilter</filter-name>
   
        
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
   
    
</filter>
 
    
<filter-mapping>
   
        
<filter-name>hibernateFilter</filter-name>
   
        
<url-pattern>*.action</url-pattern>
   
    
</filter-mapping>
 
    
    
<!-- DWR Servlet-->

  
<servlet>
    
<servlet-name>dwr-invoker</servlet-name>
    
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
    
<init-param>
      
<param-name>debug</param-name>
      
<param-value>true</param-value>
    
</init-param>
  
</servlet>

  
<servlet-mapping>
    
<servlet-name>dwr-invoker</servlet-name>
    
<url-pattern>/dwr/*</url-pattern>
  
</servlet-mapping>
  
    
<session-config>   
        
<session-timeout>10</session-timeout>
   
    
</session-config>
 
    
  
<welcome-file-list>

    
<welcome-file>index.jsp</welcome-file>
  
</welcome-file-list>
  
<error-page>
    
<error-code>401</error-code>
    
<location>/401.htm</location>
  
</error-page>
  
<error-page>
    
<error-code>403</error-code>
    
<location>/403.htm</location>
  
</error-page>
  
<error-page>
    
<error-code>404</error-code>
    
<location>/404.htm</location>
  
</error-page>
  
<error-page>
    
<error-code>500</error-code>
    
<location>/500.htm</location>
  
</error-page>
</web-app>


 

6)dwr.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://getahead.org/dwr/dwr20.dtd">

<dwr<span sty
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics