1.简要说明
这里和登录界面的区别不大,还是先看看效果吗吧。
2.注册界面代码:sign_up.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- 用于注册用户信息界面,注册完之后跳转到add.jsp -->
<html>
<head>
<!-- Page title -->
<title>用户注册</title>
<!-- End of Page title -->
<!-- Libraries -->
<link type="text/css" href="css/login.css" rel="stylesheet" />
<link type="text/css" href="css/smoothness/jquery-ui-1.7.2.custom.html" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/easyTooltip.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<!-- End of Libraries -->
</head>
<body>
<div id="container">
<div class="logo">
<a href="#"><img src="assets/logo.png" alt="" /></a>
</div>
<div id="box">
<form action="add.jsp" method="post">
<p class="main">
<label>用户名: </label>
<input name="username" value="" />
<label>密码: </label>
<input type="password" name="password" value="">
</p>
<p class="space">
<input type="submit" value="确定" class="login" name="sign_in" style="cursor: pointer;"/>
</p>
</form>
</div>
</div>
</body>
</html>
3.功能实现:add.jsp
<%@page import="com.dao.UsersDao"%>
<%@page import="com.model.User"%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!-- 获取表单注册信息的内容,往数据库中添加一条数据 -->
<%
request.setCharacterEncoding("utf-8");
String name = request.getParameter("username");
String password = request.getParameter("password");
//将用户名和密码加入到user对象中
User u=new User();
u.setName(name);
u.setPassword(password);
//将user对象添加到数据库中
UsersDao dao=new UsersDao();
try {
dao.add(u);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log("用户注册成功!");
pageContext.forward("welcome.jsp");
%>
好啦,我们的登录注册系统就大功告成啦,真是写死我啦。嗯,在这里我还有很多不足之处,如果你有什么问题或者发现什么问题,请留言告诉我,我一定会看到的~还是初学者,接触到并用到MVC的思路开发程序真的大块人心!
最后我们来看一下整个程序运行一遍的流程吧~