基于基于struts2和和hibernate实现登录和注册功能实现登录和注册功能
主要为大家详细介绍了基于struts2和hibernate实现登录和注册功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了struts2和hibernate实现登录和注册功能,供大家参考,具体内容如下
1、该项目使用MySQL数据库,数据库名为test,表名info,如图所示:
2、配置web.xml(Struts2使用)
<?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">
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3、编写视图组件(JSP页面)
(1)登录页面login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><s:text name="基于SH的登录注册系统" /></title>
</head>
<body bgcolor="#CCCCFF">
<s:form action="login" method="post">
<br><br><br><br><br><br>
<table border="1" align="center" bgcolor="AABBCCDD">
<tr>
<td>
<s:textfield name="userName" label="用户名字" size="16" />
</td>
</tr>
<tr>
<td>
<s:password name="password" label="用户密码" size="18" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<s:submit value="登录" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<s:a href="http://localhost:8080/hibernate01/register.jsp">注册</s:a>
</td>
</tr>
</table>
</s:form>
</body>
评论0