- 打印本文 关闭窗口
- 在jsp中用bean和servlet联合实现用户注册、登录
- 作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005/9/10 14:29:09
- return(cookie.getValue());
}
return(defaultValue);
}
}说明:此bean检测cookie中的username,若不为空则说明已登录,反之说明没有登录。方法不够完善,您可以自行扩充。
六、在JRun中建立shopping服务器
打开JRun Administrator,新建shopping服务器,这里端口为8101。
将上文所述所有编译后的class文件连同org包拷至JRun的shopping服务器所在目录中的classes文件夹下,路径为:
C:JRun4serversshoppingdefault-eardefault-warWEB-INFclasses七、建立jsp文件
应用DW,在C:JRun4serversshoppingdefault-eardefault-war目录下新建如下的jsp文件:
index.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="styles/shoppingstyle.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<jsp:useBean id="checklogin" class="checkLogin" scope="page"/>
<%
boolean login = checklogin.check(request,response);
%>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#990000">
<td height="80" colspan="5"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="120"> </td>
<td class="caption">Shopping123</td>
<td width="200"> </td>
</tr>
</table></td>
</tr>
<tr>
<td width="200" align="center" valign="top"><table width="100%" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr>
</table>
<%
if(!login){
%>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<form name="form1" method="post" action="/servlet/login">
<tr align="center" bgcolor="#CCCCCC">
<td height="30" colspan="2" class="deepred">卖场入口</td>
</tr>
<tr>
<td width="50%" height="24" align="center" bgcolor="#FFFFFF">会员</td>
<td align="center" bgcolor="#FFFFFF"><input name="username" type="text" id="username" size="10"></td>
</tr>
<tr>
<td height="24" align="center" bgcolor="#FFFFFF">密码</td>
<td align="center" bgcolor="#FFFFFF"><input name="password" type="text" id="password" size="10"></td>
</tr>
<tr>
<td height="24" align="center" bgcolor="#FFFFFF"><a href="reg.jsp" target="_blank" class="red">注册</a></td>
<td align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="进入"></td>
</tr>
</form>
</table>
<%
}
else
{
out.println("您好," + checklogin.getUserName() + "!");
}
%>
</td>
<td width="1" valign="top" bgcolor="#CCCCCC"></td>
<td width="400"> </td>
<td width="1" valign="top" bgcolor="#CCCCCC"></td>
<td width="200"> </td>
</tr>
<tr align="center" bgcolor="#990000">
<td height="60" colspan="5" class="white">copyright© 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="styles/shoppingstyle.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#990000">
<td height="80" colspan="5"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="120"> </td>
<td class="caption">Shopping123</td>
<td width="200"> </td>
</tr>
</table></td>
</tr>
<tr>
<td width="100" align="center" valign="top"> </td>
<td width="1" valign="top"></td>
<td width="400" align="center" valign="top"><table width="100%" height="20" border="0" cellpadding="0" cellspacing="0">
<tr>
<td> </td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<form action="regpost.jsp" method="post" name="form1">
<tr align="center">
<td height="30" colspan="2" bgcolor="#CCCCCC" class="deepred">会员注册</td>
</tr>
<tr>
<td width="50%" height="24" align="center" bgcolor="#FFFFFF">会员</td>
<td align="center" bgcolor="#FFFFFF"><input name="username" type="text" id="username" size="16"></td>
</tr>
<tr>
<td width="50%" height="24" align="center" bgcolor="#FFFFFF">密码</td>
<td align="center" bgcolor="#FFFFFF"><input name="password" type="password" id="password" size="16"></td>
</tr>
<tr>
<td width="50%" height="24" align="center" bgcolor="#FFFFFF">验证密码</td>
<td align="center" bgcolor="#FFFFFF"><input name="confirm" type="password" id="confirm" size="16"></td>
</tr>
<tr>
<td width="50%" height="24" align="center" bgcolor="#FFFFFF">E-mail</td>
<td align="center" bgcolor="#FFFFFF"><input name="email" type="text" id="email" size="16"></td>
</tr>
<tr>
<td width="50%" height="24" align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit" value="重写"></td>
<td align="center" bgcolor="#FFFFFF"><input type="submit" name="Submit2" value="注册"></td>
</tr>
</form>
</table></td>
<td width="1" valign="top"></td>
<td width="100"> </td>
</tr>
<tr align="center" bgcolor="#990000">
<td height="60" colspan="5" class="white">copyright© 2003 Shopping123</td>
</tr>
</table>
</body>
</html>
regpost.jsp:注册表单提交页面<%@ page contentType="text/html;charset=gb2312" pageEncoding=" - 打印本文 关闭窗口