本文实例为大家分享了struts2和hibernate实现登录和注册功能,供大家参考,具体内容如下
1、该项目使用MySQL数据库,数据库名为test,表名info,如图所示:
2、配置web.xml(Struts2使用)
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">
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
index.jsp
3、编写视图组件(JSP页面)
(1)登录页面login.jsp
pageEncoding="UTF-8"%>
(2)登陆成功页面success.jsp
pageEncoding="UTF-8"%>
Insert title here欢迎,登陆成功! |
(3)注册页面register.jsp
pageEncoding="UTF-8"%>
Insert title here4、业务控制器Action
(1)登录页面对应的业务控制器LoginAction.java
其中,重写valiadate()方法,进行手工验证
package loginRegisterAction;
import java.util.List;
import loginRegisterDao.LoginRegisterInfo;
import PO.UserInfoPO;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport{
private String userName;
private String password;
private String message="error";
private List list;
public String getUserName(