日期:2014-05-16  浏览次数:20418 次

struts+spring+jdbc的框架搭建

struts+spring开发框架的搭建:

? 主要是以登录界面来说明工程的搭建问题。

??1:首先当然是导入相应的架包到WebRoot下的WEB-INF下的Lib里面;

? 2:在src下面写入一个ApplicationResources.properties;

??3:在web.xml中写入配置文件,代码如下:

???

	<servlet>
		<servlet-name>action</servlet-name>
		<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
		<init-param>
			<param-name>config</param-name>
			<param-value>/WEB-INF/config/struts-config.xml,
			 </param-value>
		</init-param>
		<!-- -->
		<init-param>
			<param-name>debug</param-name>
			<param-value>3</param-value>
		</init-param>
		<init-param>
			<param-name>detail</param-name>
			<param-value>3</param-value>
		</init-param>
		<load-on-startup>0</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>action</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>login.jsp</welcome-file>
	</welcome-file-list>
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
  				/WEB-INF/config/applicationContext.xml,
  		  	</param-value>

	</context-param>
	

?4:struts-config.xml的配置代码如下:

?

<struts-config>
  <data-sources />
  <form-beans>
  <form-bean name="loginForm" type="com.xxx.comm.login.vo.LoginVO"/>
  </form-beans>
  <global-exceptions >
  </global-exceptions>
  
  <global-forwards />
  <action-mappings>
     <!-- -->
     <action name="loginForm" path="/login" scope="request" parameter="method"
            type="org.springframework.web.struts.DelegatingActionProxy">
			<forward name="success" path="/index.jsp"/>
			<forward name="error"   path="/login.jsp"/>
	 </action>
	 <action name="" path="/loginOut" scope="request" parameter="method"
            type="com.neusoft.comm.login.action.LoginOutAction">
	 </action>
		
     <!--  -->
     
  </action-mappings>

  <message-resources
		parameter="com.xxx.ApplicationResources" />
</struts-config>

?5:在applicationContext.xml中配置如下:

?

<bean id="dataSource"
		class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName">
			<value>oracle.jdbc.driver.OracleDriver</value>
		</property>
		<property name="username" value="scott"></property>
		<property name="password" value="tiger"></property>
		<property name="url"
			value="jdbc:oracle:thin:@10.400.252.111:1521:zgw">
		</property>
		<property name="maxActive" value="100000"></property>
		<property name="maxIdle" value="20"></property>
		<property name="maxWait" value="1000"></property>
	</bean>
	<!-- transactionManager -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource">
			<ref local="dataSource" />
		</property>
	</bean>
	<!-- transaction start -->
	<bean
		class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
		<property name="beanNames">
			<list>
				<value>*Bo</value>
			</list>
		</property>
		<property name="interceptorNames">
			<list>
				<value>transactionInterceptor</value>
			</list>
		</property>
	</bean>
	<bean id="transactionInterceptor"
		class="org.springframework.transaction.interceptor.TransactionInterceptor">
		<property name="transactionManager" ref="transactionManager" />
		<property name="tr