struts包的下载:http://struts.apache.org/download.cgi#struts252

string包的下载:

http://repo.spring.io/release/org/springframework/spring/%20

hibernate包的下载:http://hibernate.org/orm/

 

一、先下载好包

 

二、创建一个项目text

 

三、导入struts2 和spring

 

 

 

 然后编辑xml

 

struts的版本是2.3.3的

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

 编写一个struts.xml的文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- 上面的头,注意版本,从样例里复制过来 showcase.war\WEB-INF\src\java\struts.xml -->

<struts>

    <package name="mypck001" extends="struts-default">
        
        <action name="Index" class="myIndexAction" method="execute1">
            <result name="success">/WEB-INF/jsp/index2.jsp</result>
            <result name="error">/WEB-INF/jsp/s_tag.jsp</result>
        </action>
    </package>
</struts>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">
<!-- 上面的头,注意版本,从样例里复制过来 showcase.war\WEB-INF\src\java\struts.xml -->

<!-- include文件用于分割,实现多人并发不冲突 -->
<struts>
	<!-- 告知Struts2运行时使用Spring来创建对象 -->
	<constant name="struts.objectFactory" value="spring" />
	<include file="s001.xml" />
	<include file="s002.xml" />
	<include file="s003.xml" />
</struts>

  

 然后添加src下创建applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--头信息,注意你的spring版本号  -->
<beans xmlns="http://www.springframework.org/schema/beans"    
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
	xmlns:p="http://www.springframework.org/schema/p"  
	xmlns:aop="http://www.springframework.org/schema/aop"   
	xmlns:context="http://www.springframework.org/schema/context"  
	xmlns:jee="http://www.springframework.org/schema/jee"  
	xmlns:tx="http://www.springframework.org/schema/tx"  
	xsi:schemaLocation="
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd  
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd  
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
	http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.2.xsd  
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">

在里面配置以下代码

<bean id="myIndexAction" class="ssh.action.IndexAction" scope="prototype">
		<!-- setIs(myIndexService) -->
		<property name="is" ref="myIndexService"/>
	</bean>
	
	<!-- myIndexService = new ssh.service.IndexServiceImpl() -->
	<bean id="myIndexService" class="ssh.service.IndexServiceImpl" scope="prototype">
		<property name="id" ref="myIndexDao"/>
	</bean>
	
	<bean id="myIndexDao" class="ssh.dao.IndexDaoImpl" scope="prototype">
		<property name="c" ref="myConnection"></property>
	</bean>
	
	<bean id="myConnection" class="ssh.util.MyConnectionImpl_SQLSERVER" scope="prototype">
	</bean>

  配置hibernate代码

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
	<session-factory>
		<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
		<property name="connection.url">jdbc:sqlserver://localhost:1433;DatabaseName=CardDB</property>
		<property name="connection.username">sa</property>
		<property name="connection.password"></property>
		<!-- 每个数据库都有1个 -->
		<property name="dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
		<property name="connection.pool_size">5</property>
		<property name="show_sql">true</property>
		<property name="format_sql">true</property>
		<property name="hbm2dll.auto">update</property>		
	</session-factory>
</hibernate-configuration>

 

 框架基本搭建完成。

posted on 2016-09-09 12:11  夏末小颜  阅读(88)  评论(0)    收藏  举报