Simple SSH2 Environment Construction

Source: Internet
Author: User

I used to build SSH before, but I only used it when I learned it myself. In the company, I am doing some system maintenance, repair and makeup, and I have no chance to create a new system, after a while, I tried to build another SSH environment and found that I had forgotten it. I couldn't help it. I wrote this article here after I made a preliminary setup. I don't have to pay a lot for it in the future.

Procedure:

<1> create a web project and add the following JAR packages to the project path.

 

Annotations-api.jar

Antlr-2.7.6.jar

C3p0-0.9.1.jar

Commons-collections-3.1.jar

Commons-fileupload-1.2.1.jar

Commons-logging-1.0.4.jar

Dom4j-1.6.1.jar

Freemarker-2.3.15.jar

Hibernate3.jar

Javassist-3.9.0.GA.jar

Jta-1.1.jar

Log4j-1.2.16.jar

Mysql-connector-java-5.1.13-bin.jar

Ognl-2.7.3.jar

Org. springframework. asm-3.0.3.RELEASE.jar

Org. springframework. beans-3.0.3.RELEASE.jar

Org. springframework. context-3.0.3.RELEASE.jar

Org. springframework. Context. support-3.0.3.RELEASE.jar

Org. springframework. core-3.0.3.RELEASE.jar

Org. springframework. expression-3.0.3.RELEASE.jar

Org. springframework. jdbc-3.0.3.RELEASE.jar

Org. springframework. orm-3.0.3.RELEASE.jar

Org. springframework. transaction-3.0.3.RELEASE.jar

Org. springframework. web-3.0.3.RELEASE.jar

Slf4j-api-1.5.8.jar

Slf4j-nop-1.5.2.jar

Struts2-core-2.1.8.1.jar

Struts2-spring-plugin-2.1.8.1.jar

Xwork-core-2.1.6.jar

<2> modify the Web. xml file to support struts2. The content is as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <web-app xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns = "http://java.sun.com/xml/ns/javaee" xmlns: Web = "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi: schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id = "webapp_id" version = "2.5"> <br/> <display-Name> SSH </display-Name> <br/> <welcome- file-List> <br/> <welcome-File> index.html </welcome-File> <br/> <welcome-File> index.htm </welcome-File> <br/> <welcome-File> index. JSP </welcome-File> <br/> <welcome-File> default.html </welcome-File> <br/> <welcome-File> default.htm </welcome-File> <br/> <welcome-File> default. JSP </welcome-File> <br/> </welcome-file-List> </P> <p> <context-param> <br/> <param-Name> contextconfiglocation </param-Name> <br/> <param-value> classpath: XML/applicationcontext. XML </param-value> // specifies the path of the configuration file used by spring <br/> </context-param> <br/> <listener -Class> Org. springframework. web. context. contextloaderlistener </listener-class> <br/> </listener> <br/> <context-param> <br/> <param-Name> log4jconfiglocation </param-Name> <br/> <param-value> classpath: log4j. properties </param-value> <br/> </context-param> <br/> <param-Name> log4jrefreshinterval </param- name >>< br/> <param-value> 3000 </param-value> <br/> </context-param> <br/> <listener> <br/> <listener-class> Org. springframework. web. util. log4jconfiglistener </listener-class> // Add log4j support <br/> </listener> </P> <p> <filter> <br/> <filter-Name> struts2 </filter-Name> <br/> <filter-class> Org. apache. struts2.dispatcher. ng. filter. strutsprepareandexecutefilter </filter-class> // configure the struts2 filter to intercept user requests. <br/> </filter> <br/> <filter-mapping> <br/> <filter-name> struts2 </filter-Name> <br/> <URL-pattern>/* </url-pattern> <br/> </filter-mapping> </P> <p> </Web-app> 

<3> it turns out to be an SSH2 framework. Of course, you need to add the configuration files required for the three frameworks.

1. struts2, because it is only a basic configuration, some features may not be configured, and the content of my configuration file is also small, roughly as follows

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <! Doctype struts Public <br/> "-// Apache Software Foundation/DTD struts configuration 2.1.7/EN" <br/> "http://struts.apache.org/dtds/struts-2.1.7.dtd"> <br/> <struts> <br/> <constant name = "struts. objectfactory "value =" Spring "/> </P> <p> <include file =" XML/struts/module1.xml "> </include> <br/> </struts> <br/> 

The idea is to put some common configurations in this file. For the configuration of a specific module, write the configuration file and load it with <include>. The following content is module1.xml:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <! Doctype struts Public <br/> "-// Apache Software Foundation/DTD struts configuration 2.1.7/EN" <br/> "http://struts.apache.org/dtds/struts-2.1.7.dtd"> <br/> <struts> <br/> <package name = "product" namespace = "/product" extends = "struts-Default"> <br/> <action name = "product _ *" class =" productaction "method =" {1} "> <! -- The class used here should be the bean ID attribute in spring configuration --> <br/> <result name = "result">/WEB-INF/JSP/result. JSP </result> <br/> </Action> <br/> </package> <br/> </struts> <br/> 

2. Configure spring as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <beans xmlns = "http://www.springframework.org/schema/beans" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xmlns: context = "http://www.springframework.org/schema/context" <br/> xsi: schemalocation = "<br/> http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd <br/> http://www.springframework.org/schema/context http://www.sprin Gframework.org/schema/context/spring-context-3.0.xsd "> <br/> <context: component-scan base-package =" module1 "/> <! -- Use the annotation scan function to reduce the number of spring configuration files --> </P> <p> <bean id = "datasource" class = "org. springframework. JDBC. datasource. drivermanagerdatasource "> <br/> <property name =" driverclassname "value =" com. mySQL. JDBC. driver "/> <br/> <property name =" url "value =" JDBC: mysql: // localhost/test "/> <br/> <property name =" username "value =" root "/> <br/> <property name =" password "value =" 123456 "/> <br/> </bean> <br/> <! -- <Bean> <br/> <Jee: JNDI-lookup id = "datasource" JNDI-name = "Java: COMP/ENV/jdbc/MySQL "/> <br/> </bean> --> <! -- Some Basic Public configurations are configured in this file --> <br/> <import resource = "applicationContext-hibernate.xml"/> <! -- Separate hibernate integration configuration --> <br/> <import resource = "module1/applicationContext-module1.xml"/> <! -- Configuration of a specific module --> </P> <p> </beans> <br/> 

Spring-hibernate support

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <beans xmlns = "http://www.springframework.org/schema/beans" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xmlns: context = "http://www.springframework.org/schema/context" <br/> xsi: schemalocation = "<br/> http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd <br/> http://www.springframework.org/schema/context http://www.sprin Gframework.org/schema/context/spring-context-3.0.xsd "> <br/> <bean id =" sessionfactory "class =" org. springframework. orm. hibernate3.localsessionfactorybean "> <br/> <property name =" datasource "ref =" datasource "/> <! -- Use external datasource injection --> <br/> <property name = "mappingresources"> <br/> <list> <br/> <value> module1/Vo/product. HBM. XML </value> <! -- Configuration file of an entity --> <br/> </List> <br/> </property> <br/> <property name = "hibernateproperties"> <br/> <props> <br/> <prop key = "hibernate. dialect "> Org. hibernate. dialect. mysqldialect </prop> <br/> <prop key = "hibernate. show_ SQL "> true </prop> <br/> <prop key =" hibernate. format_ SQL "> true </prop> <br/> </props> <br/> </property> <br/> </bean> </P> <p> <! -- <Br/> <bean id = "hibernatetemplate" class = "org. springframework. orm. hibernate3.hibernatetemplate "> <br/> <property name =" sessionfactory "ref =" sessionfactory "/> <br/> </bean> <br/> --> <br/> <! -- Configure the Transaction Manager. The specific transaction management is not configured here, if you are interested, you can access the relevant information online --> <br/> <bean id = "transactionmanager" class = "org. springframework. orm. hibernate3.hibernatetransactionmanager "> <br/> <property name =" sessionfactory "ref =" sessionfactory "/> <br/> </bean> </P> <p> </beans> <br/> 

Spring-module1 Configuration

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <beans xmlns = "http://www.springframework.org/schema/beans" <br/> xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" <br/> xmlns: context = "http://www.springframework.org/schema/context" <br/> xsi: schemalocation = "<br/> http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd <br/> http://www.springframework.org/schema/context http://www.sprin Gframework.org/schema/context/spring-context-3.0.xsd "> <br/> <! -- The configuration of productaction is not seen in this configuration file because I used @ controller annotation in the class. If you are interested, you can also implement it in the annotation method, here is just an example --> <br/> <bean id = "productdao" class = "module1.dao. productdaoimpl "> <br/> <property name =" sessionfactory "ref =" sessionfactory "/> <br/> </bean> </P> <p> <bean id = "productserver" class = "module1.server. productserverimpl "> <br/> <property name =" productdao "ref =" productdao "/> <br/> </bean> </P> <p> </beans> <br/> 

Productaction content:

Package module1.action; <br/> Import javax. annotation. resource; <br/> Import module1.server. productserver; <br/> Import module1.vo. product; <br/> Import Org. apache. commons. logging. log; <br/> Import Org. apache. commons. logging. logfactory; <br/> Import Org. apache. log4j. logger; <br/> Import Org. springframework. stereotype. controller; <br/> Import COM. opensymphony. xwork2.actioncontext; <br/> import core. baseaction; <br/> @ controller // The Controller annotation is used, register it in the spring window <br/> public class productaction extends baseaction {<br/> // use the spring-implemented resource annotation for object injection, getter and setter are not even required. <br/> @ resource private productserver; <br/> private int ID; </P> <p> Public int GETID () {<br/> return ID; <br/>}< br/> Public void setid (int id) {<br/> This. id = ID; <br/>}< br/> Public String get () {<br/> log.info ("before calling server ----"); <br/> actioncontext. getcontext (). put ("result", productserver. getproductbyid (ID); <br/> log.info ("after calling server ----"); <br/> return "result "; <br/>}< br/> 

3. hibernate configuration: HBM. xml configuration files of specific object are as follows:

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <! Doctype hibernate-mapping Public <br/> "-// hibernate/hibernate DTD ing DTD 3.0/EN" <br/> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <br/> <pibernate-mapping package = "module1.vo"> <br/> <class name = "product" table = "product"> <br/> <ID name = "ID"> <br/> <generator class = "increment"/> <br/> </ID> <br/> <property name = "name" type = "string"/> <br/> <property name = "cost" type = "Java. math. bigdecimal "/> <br/> </class> <br/> </pibernate-mapping> 

 

So far, the SSH2 configuration has been completed, and a slight adjustment should be able to run the project normally. Of course, many details have not been written, please refer to the official staff for troubleshooting.

 

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.