//搭建SSH集成工程:
//1.建立普通web工程,导入SSH框架所需的jar文件(79个文件包含mysql驱动包)。
//2.建立applicationContext.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
</beans>)文件与struts-config.xml(<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
)文件。
//3.在myeclipse创建数据库连接。
//4.在applicationContext中配置数据库连接(<bean id="con" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/test?characterEncoding=GBK">
</property>
<property name="username" value="root"></property>
<property name="password" value="123"></property>
</bean>)。
//5.在applicationContext中配置HibenateSessionFactory.
//6.在工程中创建po包。
//7.在po包中创建实体与实体的映射文件。
//8.在工程中创建dao包。
//9.在dao包中创建一个类(UserDao)继承org.springframework.orm.hibernate3.support.HibernateDaoSupport。
//10.在UserDao中创建save()方法(使用getHibernateTemplate().save();).
//11.在applicationContext.xml文件中配置实体的指向(<property name="mappingResources">
<list>
<value>po/Users.hbm.xml</value>
</list>
</property>
</bean>
<bean id="UsersDAO" class="dao.UsersDAO">
<property name="sessionFactory">
<ref bean="sessionFactory"></ref>
</property>
</bean>)。
//12.在UserDao中创建Mian()进行测试(public static void main(String[] args) {
ApplicationContext ctx = new FileSystemXmlApplicationContext("WebRoot/WEB-INF/applicationContext.xml");
UsersDAO user = (UsersDAO)ctx.getBean("UsersDAO");
Users users = new Users();
users.setUsername("lbj");
users.setUpwd("123");
user.save(users);
}).
//13.在工程中创建servlet包并在包下创建并总控器类并在工程中的web.xml文件中配置总控制器(servlet和mapping各一对)(<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/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>).
//14.在工程中创建action(com.demo.sturts.action可以使用工具中右键的source中抽取方法选项快速创建save())与actionform(com.demo.sturts.form).
//15.struts.xml文件中配置struts-config信息(<struts-config>
<data-sources />
<form-beans >
<form-bean name="usersForm" type="com.demo.struts.form.UsersForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="usersForm"
input="/form/users.jsp"
name="usersForm"
path="/users"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy"/>
</action-mappings>
<message-resources parameter="com.demo.struts.ApplicationResources" />
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />
</plug-in>
</struts-config>
)
//16.在工程中创建service包并创建服务类。
//17.编写jsp页面进行测试。