独立完成的jsp样板程序代码
bs-index.jsp
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*;"%>
<html>
<head>
<title>奇迹物流管理系统</title>
<script language="javascript">
function log()
{
if(form3.log_id.value=="") //填写登陆名
{
alert("请填写用户名!");
document.form3.log_id.focus();
return false;
}
if(form3.log_pass.value=="") //填写密码
{
alert("请填写密码!");
document.form3.log_pass.focus();
return false;
}
}
</script>
</head>
<body>
<form name=form3 method="post" action="bs-log.jsp" onSubmit="return log()">
<br>
<br>
<br>
<h2 align=center><font size=6 color=red face="楷体_GB2312">奇迹物流管理系统</font></h2>
<hr width=300 color=green>
<br>
<center>
<table>
<tr>
<td width="60">用户名:</td><td width="150"><input type=text name="log_id"></td>
</tr>
<tr>
<td width="60">密 码:</td><td width="150"><input type=password name="log_pass"></td>
</tr>
<tr>
<td></td><td><a href="bs-reg.jsp"><font color=red face="楷体_GB2312">没有帐户,请点这里注册</font></a></td>
</tr>
</table>
<br>
<input type=submit value="确定"> <input type=reset value="取消">
</center>
</body>
</html>
bs-log.jsp
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*;"%>
<html>
<head>
<title>登陆提示页面</title>
<script language="javascript">
function pass()
{
if(form4.tag.value=="1") //验证用户名密码正确性
{
alert("用户名或密码错误!请返回上一页重新填写用户信息!");
document.form4.yes.focus();
return false;
}
}
</script>
</head>
<body>
<form name=form4 method="post" action="bs-log2.jsp" onSubmit="return pass();">
<%
String id=new String(request.getParameter("log_id").getBytes("8859_1"));
String password=new String(request.getParameter("log_pass"));
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/numb1.mdb");
Connection con=DriverManager.getConnection(url,"","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from reg where id='"+id+"' and pass='"+password+"'");
if(!rs.next())
{
rs.close();
%>
<input type=hidden name="tag" value="1">
<%
}
} catch (SQLException e) {
e.printStackTrace();
}
%>
<center><font color=green size="5" face="楷体_GB2312">您输入的信息是:</font></center>
<hr width="300" color=green>
<table border="1" bordercolor=blue align="center">
<tr>
<td width="80">用户名:</td><td width="150"><%=id%></td>
</tr>
<tr>
<td width="80">用户密码:</td><td width="150"><%=password%></td>
</tr>
</table>
<br>
<center><input type=submit name="yes" value="确定"></center>
</form>
</body>
</html>
bs-reg.jsp
<%@page language="java" contentType="text/html; charset=gb2312"%>
<html>
<head>
<title>欢迎注册</title>
<script language="JavaScript">
function isValid()
{
if(form1.user_id.value=="") //用户名不能为空
{
alert("用户名不能为空!");
document.form1.user_id.focus();
return false;
}
if(form1.user_id.value.length<2||form1.user_id.value.length>8) //用户名长度在2到8位
{
alert("用户名必须是6到12位之间的字符串");
document.form1.user_id.focus();
return false;
}
if(form1.user_pass.value=="") //用户密码不能为空
{
alert("密码不能为空!");
document.form1.user_pass.focus();
return false;
}
if(form1.user_pass.value.length<6||form1.user_pass.value.length>16) //用户密码长度在6到16位
{
alert("密码长度为6~16位!");
document.form1.user_pass.focus();
return false;
}
if(form1.user_pass.value!=form1.user_repass.value) //用户两次输入密码一致
{
alert("输入密码不一致!请重新输入");
document.form1.user_pass.focus();
return false;
}
if(form1.user_mail.value=="") //mail不能为空
{
alert("E-mail不能为空!");
document.form1.user_mail.focus();
return false;
}
if((form1.user_mail.value.indexOf('@',0)==-1)||(form1.user_mail.value.indexOf('.',0)==-1)) //mail格式正确
{
alert("E-mail格式不对!");
document.form1.user_mail.focus();
return false;
}
if(form1.user_address.value=="") //地址
{
alert("请输入您的注册地址!");
document.form1.user_address.focus();
return false;
}
if(form1.user_idcard.value=="") //身份证号不能为空
{
alert("身份证号不能为空!");
document.form1.user_idcard.focus();
return false;
}
if(form1.user_idcard.value.length!=18) //身份证号长度必须是18位
{
alert("请填写正确的身份证号!");
document.form1.user_idcard.focus();
return false;
}
}
</script>
</head>
<body>
<form name=form1 method="post" action="bs-reg1.jsp" onSubmit="return isValid();">
<center>
欢迎注册
<hr color=red width=500>
<table>
<tr>
<td>用户名:</td><td width="150"><input type=text name="user_id" ></td><td><font color=red>*</font> 长度为2~8位的汉字或字符串</td>
</tr>
<tr>
<td>密 码:</td><td width="150"><input type=password name="user_pass" ></td><td><font color=red>*</font> 密码长度为6~16位</td>
</tr>
<tr>
<td>确认密码:</td><td width="150"><input type=password name="user_repass"></td><td><font color=red>*</font> 请与密码输入一致</td>
</tr>
<tr>
<td>E-mail:</td><td width="150"><input type=text name="user_mail"></td><td><font color=red>*</font> 请输入正确的格式</td>
</tr>
<tr>
<td>地址:</td><td width="150"><input type=text name="user_address"></td><td><font color=red>*</font> 请输入您所居住的城市名</td>
</tr>
<tr>
<td>身份证号:</td><td width="150"><input type=text name="user_idcard"></td><td><font color=red>*</font> 请输入您的18位新身份证号</td>
</tr>
</table>
<br>
带<font color=red>*</font>项为必填项<br>
<br>
<input type=Submit value="确定"> <input type=reset value="取消">
</center>
</form>
</body>
</html>
bs-reg1.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>确认注册信息</title>
<script language="javascript">
function isOk()
{
if(form2.tag.value=="1")
{
alert("该用户已存在,请返回上一页重新填写个人信息!");
document.form2.yes.focus();
return false;
}
}
</script>
</head>
<body>
<form name=form2 method="post" action="bs-reg2.jsp" onSubmit="return isOk();">
<%@page language="java"%>
<%
String name=new String(request.getParameter("user_id").getBytes("8859_1")); //汉字也可以输入
String pass=new String(request.getParameter("user_pass").getBytes("8859_1"));
String mail=request.getParameter("user_mail");
String address=new String(request.getParameter("user_address").getBytes("8859_1"));
String idcard=request.getParameter("user_idcard");
session.putValue("uname",name);
session.putValue("upass",pass);
session.putValue("umail",mail);
session.putValue("uaddress",address);
session.putValue("uidcard",idcard);
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/numb1.mdb");
Connection con=DriverManager.getConnection(url,"","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from reg where id='"+name+"'");
if(rs.next())
{
rs.close();
%>
<input type=hidden name="tag" value="1">
<%
}
} catch (SQLException e) {
e.printStackTrace();
}
%>
<h2 align="center"><font size="5" color=black face="楷体_GB2312">个人信息</font></h2>
<hr width=350>
<table border="1" bordercolor=blue align="center">
<tr>
<td width="80">用户名</td><td width="200"><%=name%></td>
</tr>
<tr>
<td width="80">密码</td><td width="200"><%=pass%></td>
</tr>
<tr>
<td width="80">E-mail</td><td width="200"><%=mail%></td>
</tr>
<tr>
<td width="80">地址</td><td width="200"><%=address%></td>
</tr>
<tr>
<td width="80">身份证号</td><td width="200"><%=idcard%></td>
</tr>
</table>
<br>
<center><input type=submit name="yes" value="提交"></center>
</form>
</center>
</body>
</html>
bs-reg2.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<title>恭喜您注册成功!</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.style1 {
font-size: 20px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<%@page language="java"%>
<%
String un=(String)session.getValue("uname");
String up=(String)session.getValue("upass");
String um=(String)session.getValue("umail");
String ua=(String)session.getValue("uaddress");
String ui=(String)session.getValue("uidcard");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
String url="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ="+application.getRealPath("/numb1.mdb");
Connection con=DriverManager.getConnection(url,"","");
Statement stmt=con.createStatement();
int rs1=stmt.executeUpdate("insert into reg values('"+un+"','"+up+"','"+um+"','"+ua+"','"+ui+"')");
con.close();
} catch (SQLException e) {
e.printStackTrace();
}%>
<br>
<br>
<br>
<center><font size=7 face="楷体_GB2312">已提交成功!</font>
<br>
<br>
<br>
<a href="bs-index.jsp">点击跳转到主页</a></center>
</body>
</html>