ssh Project environment setup Steps of web Project

  • 2021-01-02 21:57:37
  • OfStack

1. Create Web project

2. Add Struts2 support (Struts-2.3.1.2 version)
1. Copy the relevant jar package to the lib directory
(1) struts2-core-2.3.1.2.jar
(2) xwork-core-2.3.1.2.jar
(3) ognl-3.0.4.jar
(4) freemarker-2.3.18.jar
(5) commons-logging-1.1.1.jar
(6) commons-io-2.0.1.jar
(7) commons-lang-2.5.jar
(8) commons-fileupload-1.2.2.jar
(9) javassist-3.11.0.GA.jar
(10) struts2-spring-plugin-2.3.1.2.jar(integrated Spring)

2. Configure web. xml file
(1) Open the struts-2.3.1.2 \apps\ struts2-ES41en.war file to see the configuration of ES43en.xml
(2) Copy the relevant content as follows:


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

3. Copy the ES55en.xml file in ES50en-2.3.1.2 \apps\ struts2-ES53en.war to src. The content is as follows:


<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEstrutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constantname="struts.enable.DynamicMethodInvocation"value="false"/>
<constantname="struts.devMode"value="false"/>
<packagename="default"namespace="/"extends="struts-default">
<default-action-refname="index"/>
<global-results>
<resultname="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mappingexception="java.lang.Exception"result="error"/>
</global-exception-mappings>
</package>
<!--Addpackageshere-->
</struts>

4. Add the relevant ES62en. hbm. xml file to the corresponding package, and the content is roughly as follows:


<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEhibernate-mappingPUBLIC
"-//Hibernate/HibernateMappingDTD3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mappingpackage="com.oracle.po">
<classname="CustomerBean"table="Customer">
<idname="name"column="uname"/>
<propertyname="password"column="upassword"/>
</class>
</hibernate-mapping>

3. Add Spring support (Spring-framework-2.5.6 version)

1. Copy the related jar package to the lib directory
(1)spring.jar
(2)aspectjweaver.jar

2. Copy applicationContext. xml to src directory under ES82en-ES83en-2.5.6 \samples directory and modify the file named ES88en-ES89en. xml


<?xmlversion="1.0"encoding="UTF-8"?>
<beansxmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
</beans>

3. Modify the web. xml configuration file to add the following contents:

[coe]
< ! Add listener, responsible for loading Spring file >
< listener >
< listener-class > org.springframework.web.context.ContextLoaderListener < /listener-class >
< /listener >
< ! -- Specifies the associated configuration file for Spring -- >
< context-param >
< param-name > contextConfigLocation < /param-name >
< param-value > classpath:applicationContext-*.xml < /param-value >
< /context-param >
[/code]

4. Add Hibernate support (Hibernate-distribution-3.6.10.ES155en)

1. Copy the relevant package to lib, including hibernate-ES160en-3.6.10.Final\lib\required, jar as listed below:
(1)hibernate3.jar
(2)antlr-2.7.6.jar
(3)commons-collections-3.1.jar
(4)dom4j-1.6.1.jar
(5)jta-1.1.jar
(6)slf4j-api-1.6.1.jar
(7)hibernate-jpa-2.0-api-1.0.1.Final.jar
2. Copy the DATABASE related jar files to lib, such as ES183en-ES184en-ES185en-5.1.18-ES186en.jar

5. Integration of Hibernate and Spring

1. Modify es194EN-ES195en. xml file to add the following contents:


<!--1. configuration DataSource The data source -->
<beanid="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<propertyname="driverClassName"value="com.mysql.jdbc.Driver"/>
<propertyname="url"value="jdbc:mysql://localhost:3306/MySSH"/>
<propertyname="username"value="root"/>
<propertyname="password"value="ok"/>
</bean>
<!--2. configuration SessionFactory-->
<beanid="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- injection DataSource-->
<propertyname="dataSource"ref="dataSource"/>
<!-- Map file list -->
<propertyname="mappingResources">
<list>
<value>com/oracle/po/Customer.hbm.xml</value>
</list>
</property>
<!--Hibernate Related property configuration -->
<propertyname="hibernateProperties">
<props>
<propkey="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<propkey="hibernate.show_sql">true</prop>
<propkey="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<!--3. Define the transaction manager -->
<beanid="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<propertyname="sessionFactory"ref="sessionFactory"/>
</bean>
<!--4. configuration Spring right Hibernate The propagation characteristics of transaction management -->
<tx:adviceid="txAdvice"transaction-manager="transactionManager">
<tx:attributes>
<tx:methodname="add*"propagation="REQUIRED"/>
<tx:methodname="modify*"propagation="REQUIRED"/>
<tx:methodname="del*"propagation="REQUIRED"/>
<tx:methodname="*"read-only="true"/>
</tx:attributes>
</tx:advice>
<!--5. configuration Spring right Hibernate Transaction pointcut -->
<aop:config>
<aop:pointcutexpression="execution(*com.oracle.dao.*.*(..))"id="allManagerMethod"/>
<aop:advisoradvice-ref="txAdvice"pointcut-ref="allManagerMethod"/>
</aop:config>


Related articles: