SSH整合配置

web配置

 

<?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的配置文件路径
  方式有2种一种配置到classpath路径那么就可以把applicationContext.xml放在src中就可以了
  一种配置到web-info路径
 -->
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>classpath:applicationContext.xml</param-value>
 </context-param>
 <!--struts2-->

 <!-- 定义ActionContextCleanUp过滤器 -->
 <filter>
  <filter-name>struts-cleanup</filter-name>
  <filter-class>
   org.apache.struts2.dispatcher.ActionContextCleanUp
  </filter-class>
 </filter>
 <!-- 定义SiteMesh的核心过滤器 -->

 <!-- 定义Struts2的核心过滤器 -->
 <filter>
  <filter-name>struts2</filter-name>
  <filter-class>
   org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
 </filter>
 
 
 <!-- 定义过滤器链 -->
 <!-- 排在第一位的过滤器是:ActionContextCleanUp过滤器。 -->
 <filter-mapping>
  <filter-name>struts-cleanup</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <!-- 排在第二位的过滤器是:SiteMesh核心过滤器。 -->

 


 <!-- 排在第三位的过滤器是:StrutsPrepareAndExecuteFilter过滤器。 -->
 <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 
 <!--struts2-end-->
 

 <!--dwr-->
 <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>

 <!--dwr-end-->


 <!--spring-->
 <listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>
 <!--spring-end-->

 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

 

 

applcationContext.xml配置

 

 

<?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:tx="
http://www.springframework.org/schema/tx"
 xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
 <!-- 使用dataSource提供的数据源对象 -->
 <bean id="dataSource"
  class="org.apache.commons.dbcp.BasicDataSource"
  destroy-method="close">
  <property name="driverClassName" value="com.mysql.jdbc.Driver" />
  <property name="url"
   value="jdbc:mysql://localhost:3306/sshproject?useUnicode=true&amp;characterEncoding=UTF-8" />
  <property name="username" value="root" />
  <property name="password" value="123456" />
 </bean>

 <!-- 整合hibernate -->
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource"></property>
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hbm2ddl.auto">create</prop>
   </props>
  </property>
  <property name="mappingResources">
   <list><value>com/ssp/bean/User.hbm.xml</value></list>
  </property>
 </bean>

 <bean id="MyService" class="com.ssp.service.UserServiceImpl" scope="prototype">
  <property name="sessionFactory">
   <ref bean="sessionFactory" />
  </property>
 </bean>

 <!-- 这里的这个bean的id将被struts-user.xml文件中的<action class="registerAction" 使用到。 -->
 <bean id="registerAction" class="com.ssp.action.RegisterAction" scope="prototype">
  <property name="service" ref="MyService"></property>
 </bean>

 

 

 <!-- 通过spring 管理 struts的Action创建,并使用IOC注入Action所依赖的对象
 <bean id="loginAction" class="com.ssp.action.LoginAction"
  scope="prototype">
  <property name="service" ref="service" />
 </bean> -->

 
 <!-- 获得所以用户列表, 慢慢将通过Aop进行查看限制
 <bean id="userInfoAction" class="com.ssp.action.UserInfoAction" scope="prototype">
  <property name="service" ref="service"/>
 </bean> -->
</beans>

 

 

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>
<!-- 实际开发中这里主要是配置一些共享资源 公共资源 -->
 <constant name="struts.devMode" value="true"/>
 <constant name="struts.i18n.reload" value="false"/>
 <constant name="struts.configuration.xml.reload" value="true"/>
 <!-- 通过constant 可以扩展一些自定义的访问后缀 多个使用 , 进行分割 -->
 <!--配置请求的后缀必须是action或者do 方便整合dwr2.0配置-->
 <constant name="struts.action.extension" value="action,do" />
 <!--配置freemarker模板允许后缀-->
 <!--<constant name="struts.ui.templateSuffix" value="html"/>-->

 <!-- 设置允许上传的文件大小 -->
 <constant name="struts.multipart.maxSize" value="50000000"/>
 <!-- 定义文件上传存放临时文件的目录 -->
 <constant name="struts.multipart.saveDir" value="c:/temp"/>
 
 <!-- 通过include引入其他模块配置文件,方便团队开发 --> 
 <include file="struts-user.xml"/><!--用户模块-->
</struts>

 

 

 

struts-user.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>
 <package name="ssp" namespace="/user" extends="struts-default">
  <!--
   注意这里的class对应的应该是applicationContext.xml文件中定义的bean id
   注意去applicationContext.xml中寻找loginAction
   其他的步骤和以前的配置一样,没有区别
   表示这个class是交给了Spring管理的一个实例了,由spring创建生成实例对象
   -->
  <action name="reg"><result>/register.jsp</result></action>
  <action name="log"><result>/login.jsp</result></action>

  

  <action name="register" class="registerAction" method="register">
   <result name="success">/user_index.jsp</result>
   <result name="input">/error.jsp</result>
     </action>

 </package>
</struts>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值