the packages used by hibernate-3.6.0+struts2-2.3.32+spring4.0.0+ are as follows:
Antlr-2.7.6.jar
Aopalliance-1.0.jar
Aspectjrt.jar
Aspectjweaver.jar
C3p0-0.9.1.jar
Commons-collections-3.1.jar
Commons-dbcp-1.4.jar
Commons-fileupload-1.3.2.jar
Commons-io-2.2.jar
Commons-lang3-3.2.jar
Commons-logging-1.1.3.jar
Commons-pool-1.6.jar
Dom4j-1.6.1.jar
Freemarker-2.3.22.jar
Hibernate-jpa-2.0-api-1.0.0.final.jar
Hibernate3.jar
Javassist-3.12.0.ga.jar
Jta-1.1.jar
Mysql-connector-java-5.1.42-bin.jar
Ognl-3.0.19.jar
Slf4j-api-1.6.1.jar
Spring-aop-4.0.0.release.jar
Spring-aspects-4.0.0.release.jar
Spring-beans-4.0.0.release.jar
Spring-context-4.0.0.release.jar
Spring-core-4.0.0.release.jar
Spring-expression-4.0.0.release.jar
Spring-framework-bom-4.0.0.release.jar
Spring-jdbc-4.0.0.release.jar
Spring-orm-4.0.0.release.jar
Spring-tx-4.0.0.release.jar
Spring-web-4.0.0.release.jar
Struts2-core-2.3.32.jar
Struts2-spring-plugin-2.3.32.jar
Xwork-core-2.3.32.jar
SSH Code:
User.java
Package Com.bjsxt.registration.model;
Anemia model congestion Model public
class User {
private Integer ID;
Private String username;
private String password;
Public Integer GetId () {return
ID;
}
public void SetId (Integer id) {
this.id = ID;
}
Public String GetUserName () {return
username;
}
public void Setusername (String username) {
this.username = username;
}
Public String GetPassword () {return
password;
}
public void SetPassword (String password) {
this.password = password;
}
}
User.hbm.xml
<?xml version= "1.0"?>
<! DOCTYPE hibernate-mapping public
"-//hibernate/hibernate mapping DTD 3.0//en"
"Http://www.hibernate.org/dtd /hibernate-mapping-3.0.dtd ">
<!--This mapping demonstrates," "inverse" join to map a association
table as a association with One-to-many multiplicity in the level of the
object model.-->
Userdao.java
Package Com.bjsxt.registration.dao;
Import Com.bjsxt.registration.model.User;
Public interface Userdao {
/** save data *
/public void Save (user);
/** query whether a data exists
/public boolean checkuserexistswithname (String username);
Userdaoimpl.java
Package Com.bjsxt.registration.dao.impl;
Import java.util.List;
Import org.springframework.orm.hibernate3.HibernateTemplate;
Import Com.bjsxt.registration.dao.UserDao;
Import Com.bjsxt.registration.model.User;
public class Userdaoimpl implements Userdao {
private hibernatetemplate hibernatetemplate;
Public Hibernatetemplate Gethibernatetemplate () {return
hibernatetemplate;
}
public void Sethibernatetemplate (Hibernatetemplate hibernatetemplate) {
this.hibernatetemplate = hibernatetemplate;
}
public void Save (user user) {
hibernatetemplate.save (user);
}
public boolean checkuserexistswithname (String username) {
list<object> users = Hibernatetemplate
. Find ("From User u where u.username= '" + Username + "");
if (Users!= null && users.size () > 0) {return
true;
}
return false;
}
}
Usermanager.java
Package com.bjsxt.registration.service;
Import Com.bjsxt.registration.model.User;
Public interface Usermanager {
/** to determine whether there is a
/public boolean exists (user user);
/** Add Data *
/public void Add (user user);
}
Usermanagerimpl.java
Package Com.bjsxt.registration.service.impl;
Import Com.bjsxt.registration.dao.UserDao;
Import Com.bjsxt.registration.model.User;
Import Com.bjsxt.registration.service.UserManager;
public class Usermanagerimpl implements Usermanager {
private Userdao Userdao;
Public Userdao Getuserdao () {return
Userdao;
}
public void Setuserdao (Userdao userdao) {
This.userdao = Userdao;
}
Public Boolean exists (user user) {return
userdao.checkuserexistswithname (User.getusername ());
}
public void Add (user user) {
userdao.save (user);
}
}
Useraction.java
Package com.bjsxt.registration.action;
Import Com.bjsxt.registration.model.User;
Import Com.bjsxt.registration.service.UserManager;
Import Com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings ("Serial") public class Useraction extends Actionsupport {private String username;
private String password;
Private String Password2;
Private Usermanager Usermanager;
Public String GetPassword2 () {return password2;
} public void SetPassword2 (String password2) {this.password2 = Password2;
Public String GetUserName () {return username;
} public void Setusername (String username) {this.username = username;
Public String GetPassword () {return password;
} public void SetPassword (String password) {this.password = password;
Public Usermanager Getusermanager () {return usermanager;
public void Setusermanager (Usermanager usermanager) {this.usermanager = Usermanager; @Override public String Execute () throws Exception {User user = new useR ();
User.setusername (username);
User.setpassword (password);
if (usermanager.exists (user)) {return "FAIL";
} usermanager.add (user);
return "SUCCESS";
}
}
Jdbc.properties
Jdbc.driverclassname=com.mysql.jdbc.driver
jdbc.url=jdbc\:mysql\://localhost\:3306/spring
Jdbc.username=root
Jdbc.password=root
Beans.xml
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" xmlns:
Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context" xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" xmlns:tx= "Http://www.springframework.org/schema/tx" xsi: schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/s Pring-beans.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/contex T/spring-context.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/s Pring-aop.xsd http://www.springframework.org/schema/tx Http://www.springframework.org/schema/tx/spring-tx. xsd "> <!--Dependency injection Userdaoimpl--> <bean id=" Userdaoimpl "class=" Com.bjsxt.registration.dao.impl.UserDaoImpl "> <property name=" hibernatetemplate "ref=" HibernAtetemplate "/> </bean> <!--dependency Injection Usermanagerimpl--> <bean id=" Usermanagerimpl "class=" Com.bjsxt.reg Istration.service.impl.UserManagerImpl "> <property name=" Userdao "ref=" Userdaoimpl "/> </bean> <!- -Dependency Injection useraction, each access creates a new instance--> <bean id= "useraction" class= "com.bjsxt.registration.action.UserAction" scope = "Prototype" > <property name= "Usermanager" ref= "Usermanagerimpl"/> </bean> <!--configuration DataSource
; <bean class= "Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name= " Locations "> <value>classpath:jdbc.properties</value> </property> </bean> <bean id=" da Tasource "class=" Org.apache.commons.dbcp.BasicDataSource "destroy-method=" Close "> <property name=" Driverclassname "value=" ${jdbc.driverclassname} "/> <property name=" url "value=" ${jdbc.url} "/>
Name= "username" value= "${jdbc.username}"/><property name= "Password" value= "${jdbc.password}"/> </bean> <!--configuration sessionfactory--> <bean id= "Sessionfactory" class= "Org.springframework.orm.hibernate3.LocalSessionFactoryBean" > <property name= " DataSource "ref=" DataSource "/> <property name=" mappingdirectorylocations "> <list> <value>cl asspath:com/bjsxt/registration/model/</value> </list> </property> <property name= "Hibernatepr Operties "> <props> <!--display SQL statements--> <prop key=" Hibernate.show_sql ">true</prop> & lt;!
--Automatically build table structure--> <prop key= "Hibernate.hbm2ddl.auto" >update</prop> </props> </property> </bean> <!--configuration hibernateteimplate--> <bean id= "hibernatetemplate" class= " Org.springframework.orm.hibernate3.HibernateTemplate "> <property name=" sessionfactory "ref=" Sessionfactory " /> </bean> <!--configuration transaction Txmanager--> <bean id= "TXMeanage "class=" Org.springframework.orm.hibernate3.HibernateTransactionManager "> <property name=" Sessionfactory "ref=" sessionfactory/> </bean> <!--Configure Transaction scope txadvisor--> <tx:advice id= "Txadvice" tra Nsaction-manager= "Txmeanage" > <tx:attributes> <tx:method name= "exists" read-only= "true"/> <tx:m Ethod name= "add*" propagation= "REQUIRED"/> </tx:attributes> </tx:advice> <!--configuration AOP scope--> < aop:config> <aop:pointcut expression= "Execution (public * Com.bjsxt.registration.service ...
*.*(..))" Id= "Pointcut"/> <aop:advisor advice-ref= "Txadvice" pointcut-ref= "Pointcut"/> </aop:config> </ Beans>
Struts.xml
<?xml version= "1.0" encoding= "UTF-8"?> <!
DOCTYPE struts public
"-//apache Software foundation//dtd struts Configuration 2.3//en"
"http:// Struts.apache.org/dtds/struts-2.3.dtd ">
<struts>
<!--specify open. JSP page default encoding-->
<constant Name= "struts.i18n.encoding" value= "UTF-8"/>
<!--with the spring collection, specifies that spring is responsible for the creation of the Action object (automatic assembly)-->
<constant name= "Struts.objectFactory.spring.autoWire" value= "type"/> <package "name="
Namespace= "/BJSXT" extends= "Struts-default" > <action name= "user_*"
Com.bjsxt.registration.action.UserAction "
method=" {1} ">
<result name=" SUCCESS "type=" redirect " >/registSuccess.jsp</result>
<result name= "FAIL" type= "redirect" >/registfail.jsp</result >
</action>
</package>
</struts>
Xml
<?xml version= "1.0" encoding= "UTF-8"?> <web-app version= "2.5" xmlns= "Http://java.sun.com/xml/ns/javaee" Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http ://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "> <!--Spring listener--> <context-param> <param-name >contextConfigLocation</param-name> <!--go to Classpath to find a name beans.xml file--> <param-value> classpath:beans.xml</param-value> </context-param> <listener> <listener-class> Org.springframework.web.context.contextloaderlistener</listener-class> </listener> <!--Struts2 Filter --> <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> <!--default page--> <welcome-file-list> <welcome-file>regist.jsp</
Welcome-file> </welcome-file-list> </web-app>
regist.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "GB18030"%> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
registfail.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "GB18030"%> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
registsuccess.jsp
<%@ page language= "java" import= "java.util.*" pageencoding= "GB18030"%> <!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >