zl程序教程

您现在的位置是:首页 >  后端

当前栏目

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

JSPServlet 实现 登录 联合 bean 中用 用户注册
2023-06-13 09:13:45 时间

声明:作者原创,版权所有。未经授权,不得转载
在jsp中用bean和servlet联合实现用户注册、登录

作者:imagebear
版权:imagebear

本例需要的软件和运行环境:
1、Windows2000Server操作系统
2、jdk1.4
3、JCreator2.5(java源码编辑调试器,吐血推荐!)
4、MacromediaJRunMX
5、MacromediaDreamweaverMX(非必需)
6、MySQL数据库(最好安装MySQLControlCenter)

一、数据库设计
用MySQLControlCenter打开MySQL数据库,新建数据库shopping,在其下新建表tbl_user,其中各字段设置如下:


二、编写连接数据库bean:DBConn.java


//DBConn.java

//includerequiredclasses
importjava.sql.*;

//==========================================
//DefineClassDBConn
//==========================================
publicclassDBConn
{
 publicStringsql_driver="org.gjt.mm.mysql.Driver";
 publicStringsql_url="jdbc:mysql://localhost:3306";
 publicStringsql_DBName="shopping";
 publicStringuser="sa";
 publicStringpwd=";

 Connectionconn=null;
 Statementstmt=null;
 ResultSetrs=null;

 publicbooleansetDriver(Stringdrv)
 {
 this.sql_driver=drv;
 returntrue;
 }

 publicStringgetDriver()
 {
 returnthis.sql_driver;
 }

 publicbooleansetUrl(Stringurl)
 {
 this.sql_url=url;
 returntrue;
 }

 publicbooleansetDBName(Stringdbname)
 {
 this.sql_DBName=dbname;
 returntrue;
 }

 publicStringgetDBName()
 {
 returnthis.sql_DBName;
 }

 publicbooleansetUser(Stringuser)
 {
 this.user=user;
 returntrue;
 }

 publicStringgetUser()
 {
 returnthis.user;
 }

 publicbooleansetPwd(Stringpwd)
 {
 this.pwd=pwd;
 returntrue;
 }

 publicStringgetPwd()
 {
 returnthis.pwd;
 }

 publicDBConn()
 {
 try{
  Class.forName(sql_driver);//加载数据库驱动程序
  this.conn=DriverManager.getConnection(sql_url+"/"+sql_DBName+"?user="+user+"&password="+pwd+"&useUnicode=true&characterEncoding=gb2312");
  this.stmt=this.conn.createStatement();
 }catch(Exceptione){
  System.out.println(e.toString());
 }
 }

               //执行查询操作
 publicResultSetexecuteQuery(StringstrSql)
 {
 try{
  this.rs=stmt.executeQuery(strSql);
  returnthis.rs;
 }catch(SQLExceptione){
  System.out.println(e.toString());
  returnnull;
 }catch(NullPointerExceptione){
  System.out.println(e.toString());
  returnnull;
 }
 }

               //执行数据的插入、删除、修改操作
 publicbooleanexecute(StringstrSql)
 {
 try{
  if(this.stmt.executeUpdate(strSql)==0)
   returnfalse;
  else
   returntrue;
 }catch(SQLExceptione){
  System.out.println(e.toString());
  returnfalse;
 }catch(NullPointerExceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }

               //结果集指针跳转到某一行
 publicbooleanrs_absolute(introw)
 {
 try{
  this.rs.absolute(row);
  returntrue;
 }catch(SQLExceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }

 publicvoidrs_afterLast()
 {
 try{
  this.rs.afterLast();
 }catch(SQLExceptione){
  System.out.println(e.toString());
 }
 }

 publicvoidrs_beforeFirst()
 {
 try{
  this.rs.beforeFirst();
 }catch(SQLExceptione){
  System.out.print(e.toString());
 }
 }

 publicvoidrs_close()
 {
 try{
  this.rs.close();
 }catch(SQLExceptione){
  System.out.print(e.toString());
 }
 }

 publicvoidrs_deleteRow()
 {
 try{
  this.rs.deleteRow();
 }catch(SQLExceptione){
  System.out.print(e.toString());
 }
 }

 publicbooleanrs_first()
 {
 try{
  this.rs.first();
  returntrue;
 }catch(SQLExceptione){
  System.out.print(e.toString());
  returnfalse;
 }
 }

 publicStringrs_getString(Stringcolumn)
 {
 try{
  returnthis.rs.getString(column);
 }catch(SQLExceptione){
  System.out.println(e.toString());
  returnnull;
 }
 }

               //此方法用于获取大段文本,
               //将其中的回车换行替换为<br>
               //输出到html页面
 publicStringrs_getHtmlString(Stringcolumn)
 {
 try{
  Stringstr1=this.rs.getString(column);
  Stringstr2="\r\n";
  Stringstr3="<br>";
  returnthis.replaceAll(str1,str2,str3);
 }catch(SQLExceptione){
  System.out.println(e.toString());
  returnnull;
 }
 }

               //把str1字符串中的str2字符串替换为str3字符串
 privatestaticStringreplaceAll(Stringstr1,Stringstr2,Stringstr3)
 {
 StringBufferstrBuf=newStringBuffer(str1);
    intindex=0;
 while(str1.indexOf(str2,index)!=-1)
 {
  index=str1.indexOf(str2,index);
  strBuf.replace(str1.indexOf(str2,index),str1.indexOf(str2,index)+str2.length(),str3);
  index=index+str3.length();

   str1=strBuf.toString();
 }
 returnstrBuf.toString();
 }

 publicintrs_getInt(Stringcolumn)
 {
 try{
  returnthis.rs.getInt(column);
 }catch(SQLExceptione){
  System.out.println(e.toString());
  return-1;
 }
 }

 publicintrs_getInt(intcolumn)
 {
 try{
  returnthis.rs.getInt(column);
 }catch(SQLExceptione){
  System.out.println(e.toString());
  return-1;
 }
 }

 publicbooleanrs_next()
 {
 try{
  returnthis.rs.next();
 }catch(SQLExceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }

               //判断结果集中是否有数据
 publicbooleanhasData()
 {
 try{
  booleanhas_Data=this.rs.first();  
  this.rs.beforeFirst();
  returnhas_Data;
 }catch(SQLExceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }

 publicbooleanrs_last()
 {
 try{
  returnthis.rs.last();
 }catch(SQLExceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }

 publicbooleanrs_previous()
 {
 try{
  returnthis.rs.previous();
 }catch(Exceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }

               //main方法,调试用
 publicstaticvoidmain(Stringargs[])
 {
 try{
  DBConnmyconn=newDBConn();
  //myconn.setDBName("shopping");
  //myconn.DBConn();
  //myconn.execute("InsertIntotbl_test(id,name)values("10","shandaer")");
  //myconn.execute("Updatetbl_testsetname="yyyyyyyyyyyy"whereid=10");
  //myconn.execute("Deletefromtbl_testwhereid=1");
  ResultSetrs=myconn.executeQuery("select*fromtbl_userorderbyiddesclimit1");
  //booleanhasData=myconn.hasData();
  //System.out.println("hasdata:"+hasData);
  //rs.first();
  while(myconn.rs.next()) 
  {
   intid=myconn.rs_getInt("id")+1;
   System.out.print(id);
   System.out.println(myconn.rs_getInt("id")+myconn.rs_getString("name"));

   //System.out.println("\n"+myconn.rs_getHtmlString("name"));
   //System.out.println(myconn.rs.getString("name")+myconn.rs_getInt(1));
  }
 }catch(Exceptione){
  System.err.println(e.toString());
 }
 }

}

声明:因为使用的是MySQL数据库,所以需要MySQL数据库的驱动
下载后请将org包放至DBConn.java所在目录下
以确保该bean能正常运行

 

三、编写用户注册的bean:reg.java


//reg.java

//importrequiredclasses
importjava.sql.*;

publicclassreg
{
 publicintnewID=0;
 publicbooleanresult=false;
 publicbooleanreg(Stringusername,Stringpassword,Stringconfirm,Stringemail)
 {
 try{
  if(!this.checkUser(username))
   returnfalse;
  if(!this.checkPwd(password))
   returnfalse;
  if(!this.verifyPwd(password,confirm))
   returnfalse;
  if(!this.checkEmail(email))
   returnfalse;
  if(!this.userNotExit(username))
   returnfalse;
  this.getNewID(); 
  this.result=this.register(username,password,confirm,email);
  returnthis.result;
 }catch(Exceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }//Endbooleanreg

 publicbooleancheckUser(Stringuser)
 {
 try{  
  if(user.indexOf(""")!=-1)
  {
   System.out.println("姓名中含有非法字符!");
   returnfalse;
  }else
   returntrue;
 }catch(Exceptione){
  System.out.println(e.toString());
  returnfalse;
  }
 }

 publicbooleancheckPwd(Stringpwd)
 {
 try{
  if(pwd.indexOf(""")!=-1)
  {
   System.out.println("密码中含有非法字符!");
   returnfalse;
  }else
   returntrue;
 }catch(Exceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }

 publicbooleanverifyPwd(Stringpwd,Stringconfirm)
 {
 try{
  if(!pwd.equals(confirm))
  {
   System.out.println("两次输入的密码不一致!");
   returnfalse;
  }else
   returntrue;
 }catch(Exceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }

 publicbooleancheckEmail(Stringemail)
 {
 try{
  if(email.indexOf(""")!=-1)
  {
   System.out.println("E-mail中含有非法字符!");
   returnfalse;
  }else
   returntrue;
 }catch(Exceptione){
  System.out.println(e.toString());
  returnfalse;
 }
 }

 publicbooleanuserNotExit(Stringuser)
 {
 try{
  DBConnuserDBConn=newDBConn();
  userDBConn.executeQuery("select*fromtbl_userwherename=""+user+""");
  if(userDBConn.rs_next())
  {
   System.out.println("用户名已存在,请选择其它的用户名!");
   returnfalse;
  }else
   returntrue;
 }catch(Exceptione){
  System.out.println(e.toString());
  returnfalse;
  }
 }

 publicintgetNewID()
 {
 try{
  DBConnnewIDDBConn=newDBConn();
  newIDDBConn.executeQuery("select*fromtbl_userorderbyiddesclimit1");
  if(newIDDBConn.rs_next())
  {
   this.newID=newIDDBConn.rs_getInt("id")+1;
   System.out.println(this.newID);
  }else{
   this.newID=1;
  }
  returnthis.newID;
 }catch(Exceptione){
  System.out.println(e.toString());
  return-1;
  }   
 }

 publicintgetID()
 {
 returnthis.newID;
 }

 publicbooleanregister(Stringusername,Stringpassword,Stringconfirm,Stringemail)
 {
 try{
  DBConnregDBConn=newDBConn();
  StringstrSQL="insertintotbl_user(id,name,pwd,email)values(""+this.newID+"",""+username+"",""+password+"",""+email+"")";
  regDBConn.execute(strSQL);
  returntrue;
 }catch(Exceptione){
  System.out.println(e.toString());
  returnfalse;
  }
 }

 publicstaticvoidmain(Stringargs[])
 {
 try{

  regnewreg=newreg();  

  System.out.println(newreg.reg("sssssssss","ssssss","ssssss","imagebear@163.com"));

  DBConnmyconn=newDBConn();
  myconn.executeQuery("select*fromtbl_user");
  while(myconn.rs_next())
  {
   System.out.println(myconn.rs_getInt("id")+"   "+myconn.rs_getString("name")+"   "+myconn.rs_getString("pwd")+"   "+myconn.rs_getString("email"));
  }
  System.out.println(newreg.getID());
 }catch(Exceptione){
  System.err.println(e.toString());
 }
 }
};

说明:
1、该bean文件应和上文所述DBConn.class文件放于同一目录下
2、本例主要研究注册的过程,其中的Email检测等方法并不完善,若要应用请自行设计方法

 


四、编写用户登陆的Servlet:login.java


//login.java

//importrequiredclasses
importjava.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
importjava.sql.*;

//classlogin
publicclassloginextendsHttpServlet
{
 publicvoiddoGet(HttpServletRequestreq,HttpServletResponseres)
 throwsIOException,ServletException
 {
 Stringusername=req.getParameter("username");
 Stringpassword=req.getParameter("password");
 if(this.checklogin(username,password))
 {
  Cookiemylogin=newCookie("username",username);
  mylogin.setVersion(1);
  mylogin.setPath("/");
  mylogin.setComment("Yourloginusername");
  res.addCookie(mylogin);
 }
 //Cookie[]myCookies=req.getCookies();
 //StringnameValue=this.getCookieValue(myCookies,"username","notfound");
 //PrintWriterout=res.getWriter();
 //out.println("username"+":"+nameValue);
 //out.println("TestCookieSuccess!");
 res.sendRedirect("/index.jsp");
 }

 publicvoiddoPost(HttpServletRequestreq,HttpServletResponseres)
 throwsIOException,ServletException
 {
 doGet(req,res);
 }

 publicstaticStringgetCookieValue(Cookie[]cookies,StringcookieName,StringdefaultValue)
 {
 for(inti=0;i<cookies.length;i++){
 Cookiecookie=cookies[i];
 if(cookieName.equals(cookie.getName()))
 return(cookie.getValue());
 }
 return(defaultValue);
 }



 publicbooleanchecklogin(Stringusername,Stringpassword)
 {
 try{
  DBConnloginConn=newDBConn();
  loginConn.executeQuery("select*fromtbl_userwherename=""+username+""");
  if(loginConn.rs_next())
  {
   System.out.println("Connectioncreated!");
   if(loginConn.rs_getString("pwd").trim().equals(password))
   {
    System.out.println(loginConn.rs_getString("name"));
    returntrue;
   }
   else
   {
    returnfalse;
   }
  }
  System.out.println("TestLoginSuccess!");
  returnfalse;
 }catch(Exceptione){
  System.out.println(e.toString());
  returnfalse;
  }
 }

 publicstaticvoidmain(Stringargs[])
 {
 loginmylogin=newlogin();
 System.out.println(mylogin.checklogin("shandong","shandong"));
 }

}

说明:
1、默认的jdk1.4中并没有servlet包,请至sun公司网页下载servlet.jar,放至jdk目录下的jre\lib\目录下,并在JCreator中设置jdk处添加servlet.jar包 

2、本Servlet用于检验用户名和密码,若正确则将用户名写入Cookie,完成后将当前页重定向到index.jsp页

 


五、编写检测用户是否已经登陆的bean:checkLogin.java

//checkLogin.java

//importrequiredclasses
importjava.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;

//classcheckLogin
publicclasscheckLogin
{
 publicStringusername=";

 publicbooleancheck(HttpServletRequestreq,HttpServletResponseres)
 throwsIOException,ServletException
 {
 StringcookieName="username";
 Cookie[]myCookies=req.getCookies();
 this.username=this.getCookieValue(myCookies,cookieName,"notfound");
 PrintWriterout=res.getWriter();
 if(this.username!=null)
 {  
  //out.println("早上好,"+this.username+"!");
  returntrue;
 }else{
  out.println("登陆失败!");
  returnfalse;
  }

 }

 publicStringgetUserName()
 {
 returnthis.username;
 }

 publicstaticStringgetCookieValue(Cookie[]cookies,StringcookieName,StringdefaultValue)
 {
 for(inti=0;i<cookies.length;i++){
 Cookiecookie=cookies[i];
 if(cookieName.equals(cookie.getName()))
 return(cookie.getValue());
 }
 return(defaultValue);
 }
}

说明:此bean检测cookie中的username,若不为空则说明已登录,反之说明没有登录。方法不够完善,您可以自行扩充。

 


六、在JRun中建立shopping服务器
打开JRunAdministrator,新建shopping服务器,这里端口为8101。
将上文所述所有编译后的class文件连同org包拷至JRun的shopping服务器所在目录中的classes文件夹下,路径为:


C:\JRun4\servers\shopping\default-ear\default-war\WEB-INF\classes\

七、建立jsp文件
应用DW,在C:\JRun4\servers\shopping\default-ear\default-war\目录下新建如下的jsp文件:
index.jsp:


<%@pagecontentType="text/html;charset=gb2312"pageEncoding="gb2312"%>
<html>
<head>
<title>Shopping123</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<linkhref="styles/shoppingstyle.css"rel="stylesheet"type="text/css">
</head>
<bodybgcolor="#FFFFFF"leftmargin="0"topmargin="0">
<jsp:useBeanid="checklogin"class="checkLogin"scope="page"/>
<%
 booleanlogin=checklogin.check(request,response);
%>
<tablewidth="100%"height="100%"border="0"cellpadding="0"cellspacing="0">
 <trbgcolor="#990000">
   <tdheight="80"colspan="5"><tablewidth="100%"height="100%"border="0"cellpadding="0"cellspacing="0">
       <tr>
         <tdwidth="120"> </td>
         <tdclass="caption">Shopping123</td>
         <tdwidth="200"> </td>
       </tr>
     </table></td>
 </tr>
 <tr>
   <tdwidth="200"align="center"valign="top"><tablewidth="100%"height="20"border="0"cellpadding="0"cellspacing="0">
       <tr>
         <td> </td>
       </tr>
     </table>
  <%
   if(!login){
  %>
     <tablewidth="90%"border="0"align="center"cellpadding="0"cellspacing="1"bgcolor="#CCCCCC">
  <formname="form1"method="post"action="/servlet/login">
       <tralign="center"bgcolor="#CCCCCC">
         <tdheight="30"colspan="2"class="deepred">卖场入口</td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF">会员</td>
         <tdalign="center"bgcolor="#FFFFFF"><inputname="username"type="text"id="username"size="10"></td>
       </tr>
       <tr>
         <tdheight="24"align="center"bgcolor="#FFFFFF">密码</td>
         <tdalign="center"bgcolor="#FFFFFF"><inputname="password"type="text"id="password"size="10"></td>
       </tr>
       <tr>
         <tdheight="24"align="center"bgcolor="#FFFFFF"><ahref="reg.jsp"target="_blank"class="red">注册</a></td>
         <tdalign="center"bgcolor="#FFFFFF"><inputtype="submit"name="Submit"value="进入"></td>
       </tr>
 </form>
     </table>
  <%
   }
 else
 {
  out.println("您好,"+checklogin.getUserName()+"!");
 }
  %>
  </td>
 <tdwidth="1"valign="top"bgcolor="#CCCCCC"></td>
   <tdwidth="400"> </td>
 <tdwidth="1"valign="top"bgcolor="#CCCCCC"></td>
   <tdwidth="200"> </td>
 </tr>
 <tralign="center"bgcolor="#990000">
   <tdheight="60"colspan="5"class="white">copyright©2003Shopping123</td>
 </tr>
</table>
</body>
</html>


reg.jsp<%@pagecontentType="text/html;charset=gb2312"pageEncoding="gb2312"%>
<html>
<head>
<title>Shopping123</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<linkhref="styles/shoppingstyle.css"rel="stylesheet"type="text/css">
</head>
<bodybgcolor="#FFFFFF"leftmargin="0"topmargin="0">
<tablewidth="100%"height="100%"border="0"cellpadding="0"cellspacing="0">
 <trbgcolor="#990000">
   <tdheight="80"colspan="5"><tablewidth="100%"height="100%"border="0"cellpadding="0"cellspacing="0">
       <tr>
         <tdwidth="120"> </td>
         <tdclass="caption">Shopping123</td>
         <tdwidth="200"> </td>
       </tr>
     </table></td>
 </tr>
 <tr>
   <tdwidth="100"align="center"valign="top"> </td>
   <tdwidth="1"valign="top"></td>
   <tdwidth="400"align="center"valign="top"><tablewidth="100%"height="20"border="0"cellpadding="0"cellspacing="0">
       <tr>
         <td> </td>
       </tr>
     </table>
     <tablewidth="100%"border="0"cellpadding="0"cellspacing="1"bgcolor="#CCCCCC">
  <formaction="regpost.jsp"method="post"name="form1">
       <tralign="center">
         <tdheight="30"colspan="2"bgcolor="#CCCCCC"class="deepred">会员注册</td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF">会员</td>
         <tdalign="center"bgcolor="#FFFFFF"><inputname="username"type="text"id="username"size="16"></td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF">密码</td>
         <tdalign="center"bgcolor="#FFFFFF"><inputname="password"type="password"id="password"size="16"></td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF">验证密码</td>
         <tdalign="center"bgcolor="#FFFFFF"><inputname="confirm"type="password"id="confirm"size="16"></td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF">E-mail</td>
         <tdalign="center"bgcolor="#FFFFFF"><inputname="email"type="text"id="email"size="16"></td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF"><inputtype="submit"name="Submit"value="重写"></td>
         <tdalign="center"bgcolor="#FFFFFF"><inputtype="submit"name="Submit2"value="注册"></td>
       </tr>
 </form>
     </table></td>
   <tdwidth="1"valign="top"></td>
   <tdwidth="100"> </td>
 </tr>
 <tralign="center"bgcolor="#990000">
   <tdheight="60"colspan="5"class="white">copyright©2003Shopping123</td>
 </tr>
</table>
</body>
</html>
 regpost.jsp:注册表单提交页面<%@pagecontentType="text/html;charset=gb2312"pageEncoding="gb2312"%>
<%@pageimport="reg"%>
<html>
<head>
<title>Shopping123</title>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312">
<linkhref="styles/shoppingstyle.css"rel="stylesheet"type="text/css">
</head>
<bodybgcolor="#FFFFFF"leftmargin="0"topmargin="0">
<%
 Stringusername=newString(request.getParameter("username").getBytes("ISO8859_1")).trim();
 Stringpassword=newString(request.getParameter("password").getBytes("ISO8859_1")).trim();
 Stringconfirm=newString(request.getParameter("confirm").getBytes("ISO8859_1")).trim();
 Stringemail=newString(request.getParameter("email").getBytes("ISO8859_1")).trim();
%>
<tablewidth="100%"height="100%"border="0"cellpadding="0"cellspacing="0">
 <trbgcolor="#990000">
   <tdheight="80"colspan="5"><tablewidth="100%"height="100%"border="0"cellpadding="0"cellspacing="0">
       <tr>
         <tdwidth="120"> </td>
         <tdclass="caption">Shopping123</td>
         <tdwidth="200"> </td>
       </tr>
     </table></td>
 </tr>
 <tr>
   <tdwidth="100"align="center"valign="top"> </td>
   <tdwidth="1"valign="top"></td>
   <tdwidth="400"align="center"valign="top">
<tablewidth="100%"height="20"border="0"cellpadding="0"cellspacing="0">
       <tr>
         <td> </td>
       </tr>
     </table>
<jsp:useBeanid="regID"class="reg"scope="session"/>
<%
 if(regID.reg(username,password,confirm,email))
 {
 out.print("ok");
 StringnewID=regID.getID()+";
%>
     <tablewidth="100%"border="0"cellpadding="0"cellspacing="1"bgcolor="#CCCCCC">
       <tralign="center">
         <tdheight="30"colspan="2"bgcolor="#CCCCCC"class="deepred">恭喜您,注册成功!</td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF">编号</td>
         <tdalign="center"bgcolor="#FFFFFF"><%=newID%></td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF">会员</td>
         <tdalign="center"bgcolor="#FFFFFF"><%=username%></td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF">密码</td>
         <tdalign="center"bgcolor="#FFFFFF"><%=password%></td>
       </tr>
       <tr>
         <tdwidth="50%"height="24"align="center"bgcolor="#FFFFFF">E-mail</td>
         <tdalign="center"bgcolor="#FFFFFF"><%=email%></td>
       </tr>
     </table>
<%
 out.print("<br>");
 out.print("<ahref=javascript:window.close()>关闭</a>");
 }else{
 out.print("注册失败!<br>");
 out.print("该用户名已有人使用,请使用另外的用户名!");
 out.print("<ahref=javascript:history.go(-1)>返回</a>");
 }
%>
  </td>
   <tdwidth="1"valign="top"></td>
   <tdwidth="100"> </td>
 </tr>
 <tralign="center"bgcolor="#990000">
   <tdheight="60"colspan="5"class="white">copyright©2003Shopping123</td>
 </tr>
</table>
</body>
</html>
 至此,我们已经完成了一个用户注册、登录的系统。因为这是本人自己边学边做完成的,所以代码一定有很多不完善的地方,欢迎大家批评指正。以上所有代码均经本人测试通过。