步骤:
一、创建WEB工程。
二、导入Struts。
三、加载Filters,SetCharacterEncodingFilter.java,在Tomcat 6.0\webapps\examples\WEB-INF\classes\filters目录下有,
Web.xml中配置
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>com.ssh.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
四、加载Spring
五、加载hibernate
关联相关的数据源,
//applicationContext.xml
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@101.14.12.201:1521:orcl</value>
</property>
<property name="username">
<value></value>
</property>
<property name="password">
<value></value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/ssh/Person.hbm.xml</value></list>
</property></bean>
六、创建DAO
//applicationContext.xml
<bean id="PersonDAO" class="com.ssh.PersonDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
七、配置Action
//applicationContext.xml
<bean name="/person" class="com.ssh.struts.action.PersonAction"
abstract="false" singleton="false" lazy-init="default"
autowire="default" dependency-check="default">
<property name="persondao">
<ref bean="PersonDAO"/>
</property>
</bean>
//struts-config.xml
<action
attribute="personForm"
input="/personInsert.jsp"
name="personForm"
path="/person"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="failure" path="/personInsert.jsp" />
<forward name="ok" path="/index.do" />
</action>
一、创建WEB工程。
二、导入Struts。
三、加载Filters,SetCharacterEncodingFilter.java,在Tomcat 6.0\webapps\examples\WEB-INF\classes\filters目录下有,
Web.xml中配置
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>com.ssh.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
四、加载Spring
五、加载hibernate
关联相关的数据源,
//applicationContext.xml
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="url">
<value>jdbc:oracle:thin:@101.14.12.201:1521:orcl</value>
</property>
<property name="username">
<value></value>
</property>
<property name="password">
<value></value>
</property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/ssh/Person.hbm.xml</value></list>
</property></bean>
六、创建DAO
//applicationContext.xml
<bean id="PersonDAO" class="com.ssh.PersonDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
七、配置Action
//applicationContext.xml
<bean name="/person" class="com.ssh.struts.action.PersonAction"
abstract="false" singleton="false" lazy-init="default"
autowire="default" dependency-check="default">
<property name="persondao">
<ref bean="PersonDAO"/>
</property>
</bean>
//struts-config.xml
<action
attribute="personForm"
input="/personInsert.jsp"
name="personForm"
path="/person"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="failure" path="/personInsert.jsp" />
<forward name="ok" path="/index.do" />
</action>