日期:2014-05-20 浏览次数:21066 次
${user.msg}
<s:form action="regist" method="post">
用户名:<s:textfield name="user.username" size="20"/><br/>
密码:<s:password name="user.userpassword" size="20"/><br/>
<s:submit value="注册"/>
</s:form>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<bean id="userDAOImpl" class="dao.UserDAOImpl">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<bean id="userService" class="service.UserServiceImpl2">
<property name="userDAO">
<ref local="userDAOImpl"/>
</property>
</bean>
<bean id="Regist" class="action.Regist">
<property name="userService">
<ref local="userService"/>
</property>
</bean>
<struts>
<constant name="struts.devMode" value="true"/>
<package name="Regist11" extends="struts-default" namespace="/my">
<action name="regist" class="Regist">
<result name="success">/regist.jsp</result>
</action>
</package>
</struts>
package dao;
import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import entity.User;
public class UserDAOImpl extends HibernateDaoSupport implements UserDAO {
public boolean exist(User user) {
System.out.println("正在验证数据......");
String hql="from User u where u.username='"+user.getUsername()+"'and u.userpassword='"+user.getUserpassword()+"'";
List userList=this.getHibernateTemplate().find(hql);
System.out.println("共找到数据:"+userList.size());
if(userList.size()>0&&userList!=null){
return true;
}else{
return false;
}
}
public void saveUser(User user) {
this.getHibernateTemplate().save(user);
}
}