Steps for setting up an ssh project environment (web Project)

Source: Internet
Author: User

1. Create a Web Project

Ii. Added Struts2 support (Struts-2.3.1.2)
1. Copy the 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
Commons-io-2.0.1.jar
Commons-lang-2.5.jar
Commons-fileupload-1.2.2.jar
Javassist-3.11.0.GA.jar
(10) struts2-spring-plugin-2.3.1.2.jar (Integrated Spring)

2. Configure the web. xml file
(1) Open the struts-2.3.1.2 \ apps \ struts2-blank.war file, view the web. xml configuration
(2) Copy related content as follows:
Copy codeThe Code is 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 struts. xml file in struts-2.3.1.2 \ apps \ struts2-blank.war to src, the general content is as follows:
Copy codeThe Code 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 Xxx. hbm. xml file to the corresponding package. The content is roughly as follows:
Copy codeThe Code is 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. added Spring support (Spring-framework-2.5.6)

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

2. Copy applicationContext. xml to the src directory under the spring-framework-2.5.6 \ samples Directory and change the file name to applicationContext-common.xml. The general content is as follows:
Copy codeThe Code is as follows:
<? 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 and add the following content:

[Coe]
<! -- Added listeners to load Spring files -->
<Listener>
<Listener-class> org. springframework. web. context. ContextLoaderListener </listener-class>
</Listener>
<! -- Specify the configuration file of Spring -->
<Context-param>
<Param-name> contextConfigLocation </param-name>
<Param-value> classpath: applicationContext-*. xml </param-value>
</Context-param>
[/Code]

4. Added Hibernate support (Hibernate-distribution-3.6.10.Final)

1. Copy the relevant package to lib, including the jar file under the hibernate-distribution-3.6.10.Final \ lib \ required folder, jar is listed as follows:
(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
Slf4j-api-1.6.1.jar
Hibernate-jpa-2.0-api-1.0.1.Final.jar
2, copy the jar files related to the database to the lib, such as: mysql-connector-java-5.1.18-bin.jar

5. Integrate Hibernate and Spring

1. Modify the applicationContext-common.xml file, add the following content:
Copy codeThe Code is as follows:
<! -- 1. Configure the DataSource 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. Configure SessionFactory -->
<Beanid = "sessionFactory" class = "org. springframework. orm. hibernate3.LocalSessionFactoryBean">
<! -- Inject DataSource -->
<Propertyname = "dataSource" ref = "dataSource"/>
<! -- Ing 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. Configure Spring's Propagation feature for Hibernate 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. Configure Spring's entry point for Hibernate transactions -->
<Aop: config>
<Aop: pointcutexpression = "execution (* com. oracle. dao. *. * (..)" id = "allManagerMethod"/>
<Aop: advisoradvice-ref = "txAdvice" pointcut-ref = "allManagerMethod"/>
</Aop: config>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.