在jsp中用bean和servlet联合实现用户注册、登录(5)


<%@ page contentType="text/html;charset=gb2312" pageEncoding="gb2312" %>
<html>
<head>
<title>Shopping123</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="https://www.jb51.net/styles/shoppingstyle.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<jsp:useBean scope="page"/>
<%
 boolean login = checklogin.check(request,response);
%>
<table cellpadding="0" cellspacing="0">
  <tr bgcolor="#990000">
    <td colspan="5"><table cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
          <td>Shopping123</td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td valign="top"><table cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
   <%
    if(!login){
   %>
      <table cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
   <form method="post" action="/servlet/login">
        <tr bgcolor="#CCCCCC">
          <td colspan="2">卖场入口</td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">会员</td>
          <td bgcolor="#FFFFFF"><input type="text" size="10"></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">密码</td>
          <td bgcolor="#FFFFFF"><input type="text" size="10"></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF"><a href="https://www.jb51.net/reg.jsp" target="_blank">注册</a></td>
          <td bgcolor="#FFFFFF"><input type="submit" value="进入"></td>
        </tr>
  </form>
      </table>
   <%
    }
  else
  {
   out.println("您好," + checklogin.getUserName() + "!");
  }
   %>
   </td>
 <td valign="top" bgcolor="#CCCCCC"></td>
    <td>&nbsp;</td>
 <td valign="top" bgcolor="#CCCCCC"></td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#990000">
    <td colspan="5">copyright&copy; 2003 Shopping123</td>
  </tr>
</table>
</body>
</html>


reg.jsp<%@ page contentType="text/html;charset=gb2312" pageEncoding="gb2312" %>
<html>
<head>
<title>Shopping123</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="https://www.jb51.net/styles/shoppingstyle.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<table cellpadding="0" cellspacing="0">
  <tr bgcolor="#990000">
    <td colspan="5"><table cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
          <td>Shopping123</td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td valign="top">&nbsp;</td>
    <td valign="top"></td>
    <td valign="top"><table cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
      <table cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
   <form action="regpost.jsp" method="post">
        <tr>
          <td colspan="2" bgcolor="#CCCCCC">会员注册</td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">会员</td>
          <td bgcolor="#FFFFFF"><input type="text" size="16"></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">密码</td>
          <td bgcolor="#FFFFFF"><input type="password" size="16"></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">验证密码</td>
          <td bgcolor="#FFFFFF"><input type="password" size="16"></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">E-mail</td>
          <td bgcolor="#FFFFFF"><input type="text" size="16"></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF"><input type="submit" value="重写"></td>
          <td bgcolor="#FFFFFF"><input type="submit" value="注册"></td>
        </tr>
  </form>
      </table></td>
    <td valign="top"></td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#990000">
    <td colspan="5">copyright&copy; 2003 Shopping123</td>
  </tr>
</table>
</body>
</html>
 regpost.jsp:注册表单提交页面<%@ page contentType="text/html;charset=gb2312" pageEncoding="gb2312" %>
<%@ page import="reg"%>
<html>
<head>
<title>Shopping123</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="https://www.jb51.net/styles/shoppingstyle.css" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<%
 String username = new String(request.getParameter("username").getBytes("ISO8859_1")).trim();
 String password = new String(request.getParameter("password").getBytes("ISO8859_1")).trim();
 String confirm = new String(request.getParameter("confirm").getBytes("ISO8859_1")).trim();
 String email = new String(request.getParameter("email").getBytes("ISO8859_1")).trim();
%>
<table cellpadding="0" cellspacing="0">
  <tr bgcolor="#990000">
    <td colspan="5"><table cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
          <td>Shopping123</td>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td valign="top">&nbsp;</td>
    <td valign="top"></td>
    <td valign="top">
<table cellpadding="0" cellspacing="0">
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table>
<jsp:useBean scope="session"/>
<%
 if(regID.reg(username,password,confirm,email))
 {
  out.print("ok");
  String newID = regID.getID() + ";
%>
      <table cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
        <tr>
          <td colspan="2" bgcolor="#CCCCCC">恭喜您,注册成功!</td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">编号</td>
          <td bgcolor="#FFFFFF"><%=newID%></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">会员</td>
          <td bgcolor="#FFFFFF"><%=username%></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">密码</td>
          <td bgcolor="#FFFFFF"><%=password%></td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">E-mail</td>
          <td bgcolor="#FFFFFF"><%=email%></td>
        </tr>
      </table>
<%
  out.print("<br>");
  out.print("<a href=javascript:window.close()>关闭</a>");
 }else{
  out.print("注册失败!<br>");
  out.print("该用户名已有人使用,请使用另外的用户名!");
  out.print("<a href=javascript:history.go(-1)>返回</a>");
 }
%>
   </td>
    <td valign="top"></td>
    <td>&nbsp;</td>
  </tr>
  <tr bgcolor="#990000">
    <td colspan="5">copyright&copy; 2003 Shopping123</td>
  </tr>
</table>
</body>
</html>
 至此,我们已经完成了一个用户注册、登录的系统。 因为这是本人自己边学边做完成的,所以代码一定有很多不完善的地方,欢迎大家批评指正。 以上所有代码均经本人测试通过。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzxdxg.html