Posts Tagged ‘中用’

ASP.NET中用healthMonitor属性用法

星期二, 06月 3rd, 2008

  在ASP.NET 2.0中,可以使用healthMonitoring属性监测事件.healthMonitoring属性是一个基于方法deprovider,在这里可以构造自己deprovider.利用healthMonitoring属性,我可以诸如记录错语、成功de事件等,对不同de数据源,如事件日志,Sql Server甚至对于自己通过继承WebEventProvider类创建自己deproviders.在此文章中,我打算介绍配置一个监测SqlServer错语de并且对某人de电子信箱地址发送邮件deweb应用程序.首先,看一下在web.config中dehealthMonitoring程序片段,在此可以建立将要用到de事件.

<healthMonitoring Enabled=”true|false” heartBeatInterval=”time interval”>
 <bufferModes>… </bufferModes>
 <providers>… </providers>
 <eventMappings>… </eventMappings>
 <profiles>… </profiles>
 <rules>… </rules>
</healthMonitoring>

  如果看一下<healthMonitoring>元素,就可以判断是否可以将设置属性为有效或无效,也可以指定对WebHeaderBeatEvent被唤醒de时间间隔.healthMonitoring有5个孩子.

  bufferModes,在此可以定义一个Providerde缓冲区大小.

  Providers,在此说明处理事件deProviders.

  eventMappings, 在此可以画出与友好事件类型相关de事件名称.

  profiles, 在此定义一个可以用来配置事件de参数集集合.

  rules, 在此画出Providersde事件图.

  可以阅读更多含在VS 2550文档中de关于这些元素de东西.

  在继续之前,这里有一份含ASP.NET中de一些Providers清单:

System.Web.Management.MailWebEventProvider
System.Web.Management.SimpleMailWebEventProvider
System.Web.Management.TemplatedMailWebEventProvider
System.Web.Management.TraceWebEventProvider
System.Web.Management.EventLogWebEventProvider
System.Web.Management.SqlWebEventProvider
System.Web.Management.WmiWebEventProvider

  不需要解释这些,名字告诉我它们是干什么de.还要提一下SqlWebEventProvider依靠Sql server而工作,它将事件存储在aspnet_Web_Event表.为了安装此数据库,必须运行位于framework文件夹中deaspnet_regsql.exe向导.

  现在,配置对Sql server provider有登录错语并且发送一个电子邮件而产生错误de程序.

  下面是一个使用SqlWebEventProvider和SimpleMailWebEventProvider来存错语事件de例子.

<healthMonitoring enabled=”true” heartBeatInterval=”0″>
<bufferModes>
<add name=”Critical Notification” maxBufferSize=”100″ maxFlushSize=”20″urgentFlushThreshold=”1″ regularFlushInterval=”Infinite” urgentFlushInterval=”00:01:00″ maxBufferThreads=”1″/>

<add name=”Analysis” maxBufferSize=”1000″ maxFlushSize=”100″ urgentFlushThreshold=”100″
regularFlushInterval=”00:05:00″ urgentFlushInterval=”00:01:00″ maxBufferThreads=”1″/>

</bufferModes>
<providers>

<add name=”CriticalMailEventProvider” type=”System.Web.Management.SimpleMailWebEventProvider, System.Web …” from=info@nsquared2.net to=fnormen@hotmail.com priority=”High” bodyHeader=”Warning!”
bodyFooter=”Please investigate ASAP.” subjectPrefix=”Action required.” buffer=”true” bufferMode=”Critical Notification” maxEventLength=”4096″ maxSize=”4096″ maxMessagesPerNotification=”1″/>

<add name=”SqlWebEventProvider” type=”System.Web.Management.SqlWebEventProvider, System.Web …”
connectionStringName=”LocalSqlServer” maxEventDetailsLength=”1073741823″ buffer=”true”
bufferMode=”Analysis”/>

</providers>

<eventMappings>

<add name=”All Errors” type=”System.Web.Management.WebBaseErrorEvent, System.Web …”/>
<add name=”Request Processing Errors” type=”System.Web.Management.WebRequestErrorEvent, System.Web …/>

</eventMappings>

<profiles>

<add name=”Default” minInstances=”1″ maxLimit=”Infinite” minInterval=”00:10:00″/>

</profiles>

<rules>

<add name=”All Errors Default” eventName=”All Errors” provider=”SqlWebEventProvider” profile=”Default”
minInterval=”00:00:30″/>

<add name=”Request Processing Errors” eventName=”Request Processing Errors” provider=”CriticalMailEventProvider” profile=”Default”/>

</rules>

</healthMonitoring>

  在此例子中,使用Sql provider来记录所有错语事件,并且当Web请求错误事件被唤醒时使用mail provider来发送一个消息.

  这里有一些ASP .NET 2.0一起发布de事件:

System.Web.Management.WebBaseEvent
System.Web.Management.WebHeartBeatEvent
System.Web.Management.WebApplicationLifetimeEvent
System.Web.Management.WebRequestEvent
System.Web.Management.WebBaseErrorEvent
System.Web.Management.WebErrorEvent
System.Web.Management.WebRequestErrorEvent
System.Web.Management.WebAuditEvent
System.Web.Management.WebFailureAuditEvent
System.Web.Management.WebSuccessAuditEvent
System.Web.Management.WebManagementEvent
System.Web.Management.WebViewStateFailureAuditEvent
System.Web.Management.WebAuthenticationFailureAuditEvent
System.Web.Management.WebAuthenticationSuccessAuditEvent

  可以使用这些事件来对一个provider画图.也可以创建通过WebBaseEvent类继承来de自己de事件.

  为自动唤醒一个事件,可以使用WebBaseEvent类de唤醒方法:

try
{
 //….
}

catch(Exception e)
{
 if (HealthMonitoringManager.Enabled)
 {
  WebBaseEvent.Raise(new WebErrorEvent(”My Error message”, null, 5000, e));
 }
}

or:

if (HealthMonitoringManager.Enabled)
{
 WebErrorEvent event = new WebErrorEvent(”My error message”, null, 5000, e);
 event.Raise();
}

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

星期一, 06月 2nd, 2008

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

作者:imagebear
版权:imagebear

本例需要de软件和运行环境:
1、Windows2000 Server操作系统
2、jdk1.4
3、JCreator2.5(java源码编辑调试器,吐血推荐!)
4、Macromedia JRun MX
5、Macromedia Dreamweaver MX(非必需)
6、MySQL数据库(最好安装MySQL Control Center)

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


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


//DBConn.java

//include required classes
import java.sql.*;

//==========================================
// Define Class DBConn
//==========================================
public class DBConn
{
public String sql_driver = “org.gjt.mm.mysql.Driver”;
public String sql_url = “jdbc:mysql://localhost:3306″;
public String sql_DBName = “shopping”;
public String user = “sa”;
public String pwd = “;

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

public boolean setDriver(String drv)
{
this.sql_driver = drv;
return true;
}

public String getDriver()
{
return this.sql_driver;
}

public boolean setUrl(String url)
{
this.sql_url = url;
return true;
}

public boolean setDBName(String dbname)
{
this.sql_DBName = dbname;
return true;
}

public String getDBName()
{
return this.sql_DBName;
}

public boolean setUser(String user)
{
this.user = user;
return true;
}

public String getUser()
{
return this.user;
}

public boolean setPwd(String pwd)
{
this.pwd = pwd;
return true;
}

public String getPwd()
{
return this.pwd;
}

public DBConn()
{
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(Exception e){
System.out.println(e.toString());
}
}

//执行查询操作
public ResultSet executeQuery(String strSql)
{
try{
this.rs = stmt.executeQuery(strSql);
return this.rs;
}catch(SQLException e){
System.out.println(e.toString());
return null;
}catch(NullPointerException e){
System.out.println(e.toString());
return null;
}
}

//执行数据de插入、删除、修改操作
public boolean execute(String strSql)
{
try{
if(this.stmt.executeUpdate(strSql) == 0)
return false;
else
return true;
}catch(SQLException e){
System.out.println(e.toString());
return false;
}catch(NullPointerException e){
System.out.println(e.toString());
return false;
}
}

//结果集指针跳转到某一行
public boolean rs_absolute(int row)
{
try{
this.rs.absolute(row);
return true;
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
}

public void rs_afterLast()
{
try{
this.rs.afterLast();
}catch(SQLException e){
System.out.println(e.toString());
}
}

public void rs_beforeFirst()
{
try{
this.rs.beforeFirst();
}catch(SQLException e){
System.out.print(e.toString());
}
}

public void rs_close()
{
try{
this.rs.close();
}catch(SQLException e){
System.out.print(e.toString());
}
}

public void rs_deleteRow()
{
try{
this.rs.deleteRow();
}catch(SQLException e){
System.out.print(e.toString());
}
}

public boolean rs_first()
{
try{
this.rs.first();
return true;
}catch(SQLException e){
System.out.print(e.toString());
return false;
}
}

public String rs_getString(String column)
{
try{
return this.rs.getString(column);
}catch(SQLException e){
System.out.println(e.toString());
return null;
}
}

//此方法用于获取大段文本,
//将其中de回车换行替换为<br>
//输出到html页面
public String rs_getHtmlString(String column)
{
try{
String str1 = this.rs.getString(column);
String str2 = “\r\n”;
String str3 = “<br>”;
return this.replaceAll(str1,str2,str3);
}catch(SQLException e){
System.out.println(e.toString());
return null;
}
}
//把str1字符串中destr2字符串替换为str3字符串
private static String replaceAll(String str1,String str2,String str3)
{
StringBuffer strBuf = new StringBuffer(str1);
int index=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();
}
return strBuf.toString();
}

public int rs_getInt(String column)
{
try{
return this.rs.getInt(column);
}catch(SQLException e){
System.out.println(e.toString());
return -1;
}
}

public int rs_getInt(int column)
{
try{
return this.rs.getInt(column);
}catch(SQLException e){
System.out.println(e.toString());
return -1;
}
}

public boolean rs_next()
{
try{
return this.rs.next();
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
}

//判断结果集中是否有数据
public boolean hasData()
{
try{
boolean has_Data = this.rs.first();
this.rs.beforeFirst();
return has_Data;
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
}

public boolean rs_last()
{
try{
return this.rs.last();
}catch(SQLException e){
System.out.println(e.toString());
return false;
}
}

public boolean rs_previous()
{
try{
return this.rs.previous();
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}

//main方法,调试用
public static void main(String args[])
{
try{
DBConn myconn = new DBConn();
//myconn.setDBName(”shopping”);
//myconn.DBConn();
//myconn.execute(”Insert Into tbl_test(id,name) values(’10′,’shandaer’)”);
//myconn.execute(”Update tbl_test set name=’yyyyyyyyyyyy’ where id=10″);
//myconn.execute(”Delete from tbl_test where id=1″);
ResultSet rs = myconn.executeQuery(”select * from tbl_user order by id desc limit 1″);
//boolean hasData = myconn.hasData();
//System.out.println(”has data:” hasData);
//rs.first();
while (myconn.rs.next())
{
int id = 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(Exception e){
System.err.println(e.toString());
}
}
}

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

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


//reg.java

//import required classes
import java.sql.*;

public class reg
{
public int newID = 0;
public boolean result = false;
public boolean reg(String username,String password,String confirm,String email)
{
try{
if(!this.checkUser(username))
return false;
if(!this.checkPwd(password))
return false;
if(!this.verifyPwd(password,confirm))
return false;
if(!this.checkEmail(email))
return false;
if(!this.userNotExit(username))
return false;
this.getNewID();
this.result = this.register(username,password,confirm,email);
return this.result;
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}//End boolean reg
public boolean checkUser(String user)
{
try{
if(user.indexOf(”‘”)!=-1)
{
System.out.println(”姓名中含有非法字符!”);
return false;
}else
return true;
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}
public boolean checkPwd(String pwd)
{
try{
if(pwd.indexOf(”‘”)!=-1)
{
System.out.println(”密码中含有非法字符!”);
return false;
}else
return true;
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}
public boolean verifyPwd(String pwd,String confirm)
{
try{
if(!pwd.equals(confirm))
{
System.out.println(”两次输入de密码不一致!”);
return false;
}else
return true;
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}
public boolean checkEmail(String email)
{
try{
if(email.indexOf(”‘”)!=-1)
{
System.out.println(”E-mail中含有非法字符!”);
return false;
}else
return true;
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}
public boolean userNotExit(String user)
{
try{
DBConn userDBConn = new DBConn();
userDBConn.executeQuery(”select * from tbl_user where name=’” user “‘”);
if(userDBConn.rs_next())
{
System.out.println(”用户名已存在,请选择其它de用户名!”);
return false;
}else
return true;
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}
public int getNewID()
{
try{
DBConn newIDDBConn = new DBConn();
newIDDBConn.executeQuery(”select * from tbl_user order by id desc limit 1″);
if(newIDDBConn.rs_next())
{
this.newID = newIDDBConn.rs_getInt(”id”) 1;
System.out.println(this.newID);
}else{
this.newID = 1;
}
return this.newID;
}catch(Exception e){
System.out.println(e.toString());
return -1;
}
}
public int getID()
{
return this.newID;
}
public boolean register(String username,String password,String confirm,String email)
{
try{
DBConn regDBConn = new DBConn();
String strSQL = “insert into tbl_user(id,name,pwd,email) values(’” this.newID “‘,’” username “‘,’” password “‘,’” email “‘)”;
regDBConn.execute(strSQL);
return true;
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}

public static void main(String args[])
{
try{
reg newreg = new reg();
System.out.println(newreg.reg(”sssssssss”,”ssssss”,”ssssss”,”imagebear@163.com”));
DBConn myconn = new DBConn();
myconn.executeQuery(”select * from tbl_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(Exception e){
System.err.println(e.toString());
}
}
};

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


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


//login.java

//import required classes
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

//class login
public class login extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException
{
String username = req.getParameter(”username”);
String password = req.getParameter(”password”);
if(this.checklogin(username,password))
{
Cookie mylogin = new Cookie(”username”,username);
mylogin.setVersion(1);
mylogin.setPath(”/”);
mylogin.setComment(”Your login username”);
res.addCookie(mylogin);
}
//Cookie[] myCookies = req.getCookies();
//String nameValue = this.getCookieValue(myCookies,”username”,”not found”);
//PrintWriter out = res.getWriter();
//out.println(”username” “:” nameValue);
//out.println(”Test Cookie Success!”);
res.sendRedirect(”/index.jsp”);
}
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException
{
doGet(req,res);
}
public static String getCookieValue(Cookie[] cookies,String cookieName,String defaultValue)
{
for(int i=0;i<cookies.length;i ) {
Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName()))
return(cookie.getValue());
}
return(defaultValue);
}


public boolean checklogin(String username,String password)
{
try{
DBConn loginConn = new DBConn();
loginConn.executeQuery(”select * from tbl_user where name=’” username “‘”);
if(loginConn.rs_next())
{
System.out.println(”Connection created!”);
if(loginConn.rs_getString(”pwd”).trim().equals(password))
{
System.out.println(loginConn.rs_getString(”name”));
return true;
}
else
{
return false;
}
}
System.out.println(”Test Login Success!”);
return false;
}catch(Exception e){
System.out.println(e.toString());
return false;
}
}
public static void main(String args[])
{
login mylogin = new login();
System.out.println(mylogin.checklogin(”shandong”,”shandong”));
}
}

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

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


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

//checkLogin.java

//import required classes
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

//class checkLogin
public class checkLogin
{
public String username = “;
public boolean check(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException
{
String cookieName = “username”;
Cookie[] myCookies = req.getCookies();
this.username = this.getCookieValue(myCookies,cookieName,”not found”);
PrintWriter out = res.getWriter();
if(this.username != null)
{
//out.println(”早上好,” this.username “!”);
return true;
}else{
out.println(”登陆失败!”);
return false;
}
}
public String getUserName()
{
return this.username;
}
public static String getCookieValue(Cookie[] cookies,String cookieName,String defaultValue)
{
for(int i=0;i<cookies.length;i ) {
Cookie cookie = cookies[i];
if (cookieName.equals(cookie.getName()))
return(cookie.getValue());
}
return(defaultValue);
}
}

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


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


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

七、建立jsp文件
应用DW,在C:\JRun4\servers\shopping\default-ear\default-war\目录下新建如下dejsp文件:
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=”gb2312″ %>
<%@ page import=”reg”%>
<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″>
<%
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 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>
<jsp:useBean id=”regID” class=”reg” scope=”session”/>
<%
if(regID.reg(username,password,confirm,email))
{
out.print(”ok”);
String newID = regID.getID() “;
%>
<table width=”100%” border=”0″ cellpadding=”0″ cellspacing=”1″ bgcolor=”#CCCCCC”>
<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”><%=newID%></td>
</tr>
<tr>
<td width=”50%” height=”24″ align=”center” bgcolor=”#FFFFFF”>会员</td>
<td align=”center” bgcolor=”#FFFFFF”><%=username%></td>
</tr>
<tr>
<td width=”50%” height=”24″ align=”center” bgcolor=”#FFFFFF”>密码</td>
<td align=”center” bgcolor=”#FFFFFF”><%=password%></td>
</tr>
<tr>
<td width=”50%” height=”24″ align=”center” bgcolor=”#FFFFFF”>E-mail</td>
<td align=”center” bgcolor=”#FFFFFF”><%=email%></td>
</tr>
</table>
<%
out.print(”<br>”);
out.print(”<a href=javascript:window.close()>关闭</a>”);
}else{
out.print(”注册失败!<br>”);
out.print(”该用户名已有人使用,请使用另外de用户名!”);
out.print(”<a href=javascript:history.go(-1)>返回</a>”);
}
%>
</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>
至此,我已经完成了一个用户注册、登录de系统. 因为这是本人自己边学边做完成de,所以相关代码一定有很多不完善de地方,欢迎大家批评指正. 以上所有相关代码均经本人测试通过.