SSH environment built to your capabilities

Source: Internet
Author: User

Little Wolf recently, built an SSH environment, to share with you

Development environment: Windows7, jdk1.6 myeclispe8.6 tomcat6.0.18 mysql5.0


JAR file Required:

Junit:junit.jar

Db:mysql-connector-java-5.1.10-bin.jar

hibernate3.5.6:

Jstl:

spring2.5.5:

struts2:


Project Catalog:

Configuration file:

Xml

<listener><listener-class>org.springframework.web.context.contextloaderlistener</listener-class ></listener><context-param><param-name>contextConfigLocation</param-name>< param-value>classpath:applicationcontext.xml</param-value></context-param><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>
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" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" Xmlns:tx = "Http://www.springframework.org/schema/tx" xmlns:context= "Http://www.springframework.org/schema/context" xsi: schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schem                            A/beans/spring-beans-2.5.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP Http://www.springframework.org/schema/aop/spring-aop-2.5.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SC                           Hema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/      Spring-tx-2.5.xsd "> <import resource= "Applicationcontext-db.xml"/> <import resource= "Applicationcontext-user.xml"/> & Lt;/beans>
Applicationcontext-db.xml

<bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property Name= "Configlocation" > <value>classpath:hibernate.cfg.xml</value> </property> &LT;/BEAN&G           T <bean id= "TransactionManager" class= "Org.springframework.orm.hibernate3.HibernateTransactionManager" > < Property name= "Sessionfactory" > <ref bean= "sessionfactory"/> </property> </bean> &lt ; Tx:advice transaction-manager= "TransactionManager" id= "TX" > <tx:attributes> <tx:method name= "save*" R Ead-only= "false"/> <tx:method name= "update*" read-only= "false"/> <tx:method name= "delete*" read-only= " False "/> <tx:method name=" * "read-only=" true "/> </tx:attributes> </tx:advice> &L t;aop:config> <aop:pointcut expression= "Execution (* qh.zcy.service.*.* (..))" id= "perform"/> <aop:advis or advice-ref= "TX" POIntcut-ref= "perform"/> </aop:config>    
Applicationcontext-user.xml

        <bean id= "Userdao" class= "Qh.zcy.dao.UserDao" >          <property name= "sessionfactory" ref= "Sessionfactory" ></property>       </bean>       <bean id= "UserService" class= "Qh.zcy.service.UserService" >          <property name= "DAO" ref= "Userdao" ></property>       </bean>       <bean id= "Useraction" class= "Qh.zcy.action.UserAction" scope= "prototype" >           <property name= "service" ref= "UserService" ></ Property>       </bean>
Hibernate.cfg.xml


<?xml version= ' 1.0 ' encoding= ' UTF-8 '? ><! DOCTYPE hibernate-configuration Public "-//hibernate/hibernate configuration DTD 3.0//en" "http://www.hibernate.org/ Dtd/hibernate-configuration-3.0.dtd ">
Struts.xml

<?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE struts Public "-//apache software foundation//dtd struts Configuration 2.1.7//en" "http://struts.apache.org/ Dtds/struts-2.1.7.dtd "><struts>   <!--profile changed without rebooting and   <constant name=" Struts.devmode " Value= "true"/>            <package name= "SSH" extends= "Struts-default" namespace= "/" >         <action name= " Useraction_* "class=" useraction "method=" {1}user "></action>      </package></struts>

Useraction.jave

Package Qh.zcy.action;import Org.springframework.transaction.annotation.propagation;import Org.springframework.transaction.annotation.transactional;import Com.opensymphony.xwork2.actionsupport;import Qh.zcy.entity.user;import Qh.zcy.service.UserService; @Transactional (propagation=propagation.required) public Class Useraction extends Actionsupport{private userservice service;public userservice getService () {return service;} public void Setservice (UserService service) {this.service = service;} Public String Listuser () throws Exception {//TODO auto-generated method StubSystem.out.println (Service.getusers ()); return null;} Public String Saveuser () throws Exception {//TODO auto-generated method stubuser user=new User (); User.setpassword ("Zhang "); User.setusername (" Zhang "); Service.saveuser (user); return null;}}

Now that the SSH environment is set up, test it:

Http://localhost:8080/SSH/userAction_save.action

The console output is as follows:


SSH environment built to your capabilities

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.