ssh框架搭建(struts2)

   前天,帮同学写程序。他们公司用struts2.0,而我也没用过struts2,索性借此学习一下struts2吧。发现struts2结合spring搭建,不像struts那样要在struts配置spring插件,貌似已经在filter做好了。先将配置文件展出,供初学者参考。

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>
	
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/applicationContext*.xml</param-value>
	</context-param>
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

 

2.spring.xml

 <!-- 配置数据源 -->
  <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
       <property name="driverClassName">
               <value>com.mysql.jdbc.Driver</value> 
       </property>
       <property name="url">
               <value>jdbc:mysql://localhost:3306/temp</value>
       </property>
       <property name="username">
                <value>root</value>
       </property>
       <property name="password">
                 <value>yoyi</value>
       </property>
  </bean>
  <!-- 配置sessionFactory -->
  <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <!-- 加载数据源 -->
      <property name="dataSource">
          <ref bean="dataSource"/>
      </property>
      <!-- hibernate相应信息配置 -->
      <property name="hibernateProperties">
          <props>
             <prop key="hibernate.dialect">
                org.hibernate.dialect.MySQLDialect
             </prop>
             <prop key="hibernate.show_sql">
				 true
			 </prop>
          </props>
      </property>
      <!-- 配置pojo中*.hbm.xml加载 -->
      <property name="mappingResources">
        <list>
          <value>com/bookmanager/LendBook/pojo/Book.hbm.xml</value>
          <value>com/bookmanager/LendBook/pojo/LendBook.hbm.xml</value>
          <value>com/bookmanager/LendBook/pojo/User.hbm.xml</value>
          
        </list>
      </property>
     
  </bean>
  <!-- 配置spring管理hibernate模板 -->
  <bean id="hibernateTemplate"
		class="org.springframework.orm.hibernate3.HibernateTemplate">
		<property name="sessionFactory">
			<ref bean="sessionFactory" />
		</property>
	</bean>
  <!-- DAO注入配置 -->
  <bean id="lendBookDAO" class="com.bookmanager.LendBook.dao.LendBookDAO" abstract="true"/>
  <bean id="lendBookDAOImpl" class="com.bookmanager.LendBook.dao.impl.LendBookDAOImpl" parent="lendBookDAO">
      <property name="hibernateTemplate">
             <ref bean="hibernateTemplate"/>
         </property>
  </bean>
  <!--  Service注入配置 -->
  <bean id="lendBookService" class=" com.bookmanager.LendBook.service.LendBookService" abstract="true"/>
  <bean id="lendBookServiceImpl" class="com.bookmanager.LendBook.service.impl.LendBookServiceImpl" parent="lendBookService">
         <property name="lendBookDAOImpl">
             <ref bean="lendBookDAOImpl"/>
         </property>
  </bean>
  <!-- 登陆 -->
  <bean name="loginAction" class="com.bookmanager.LendBook.action.LoginAction">
     <property name="lendBookServiceImpl">
         <ref bean="lendBookServiceImpl"/>
     </property>
  </bean>

 3.struts.xml

<constant name="struts.devMode" value="true"></constant>
    <package name="struts2" extends="struts-default">
    <!-- action交给spring管理,class对应spring配置中的bean ,制定method后action可以不必继承ActionSupport-->
       <action name="login" class="loginAction" method="login">
       		<result name="success">/jsp/index.jsp</result>
            <result name="error">/jsp/error.jsp</result> 
       </action>
 </package>

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值