Struts + Spring +ibatis 整合开发步骤:
一.添加Spring 、Struts框架对web.xml文件的修改
1.添加Spring框架
2.在web.xml中引入Spring配置文件(注意:applicationContext.xml文件的路径)
/WEB-INF/conf/applicationContext.xml
org.springframework.web.context.ContextLoaderServlet
3.添加Struts框架
4.在web.xml中引入Spring配置文件(注意:struts-config.xml文件的路径)
org.apache.struts.action.ActionServlet
5.web.xml自动添加的*.jsp文件起始路径(注意:jsp文件的访问路径)
二、对Spring配置文件applicationContext.xml文件的修改
1.配置JDBC数据源驱动文件jdbc.properties(服务器、端口、账户、密码因具体情况而定)
MySql:
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/test
https://www.doczj.com/doc/6e16271599.html,ername=root
jdbc.password=admin
Oracle:
jdbc.driver=oracle.jdbc.driver.OracleDriver
jdbc.url=jdbc:oracle:thin:@127.0.0.1:1521:orcl
https://www.doczj.com/doc/6e16271599.html,ername=scott
jdbc.password=tiger
MS Sql Server:
jdbc.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
jdbc.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=mssql
https://www.doczj.com/doc/6e16271599.html,ername=sa
jdbc.password=sa
2.将JDBC驱动源文件部署到ApplicationContext.xml配置文件中
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
3.将Data Source配置到ApplicationContext文件中
destroy-method="close">
4.在Spring配置中注入3中的datasource数据源
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
5.引入具体的sql语句配置文件(注意:sqlMapConfig.xml文件的路径)
c lass="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
6.注入操作数据库的dao(empDao是举例)
三.对Struts配置文件struts-config.xml文件的修改
1.填写form-bean
2.填写action-mapping
name="empForm" path="/queryEmp" type="org.springframework.web.struts.DelegatingActionProxy" scope="request" >
3.填写message-resource 和plug-in(注意:action-servlet.xml文件路径)
property="contextConfigLocation"value="/conf/applicationContext.xml" /> 4.Spring与Struts相对用的配置applicationContext.xml 附一:配置文件示意图如下 附二:包结构