10.23

今天学习了用户注册界面

Login.html:


<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登陆界面Login</title>

<script>
function submit()
{
var s;
s=login.user;
if(s.value=="")
{alert("用户名是不能为空,注册失败");}
s.focus();
}
function check(t)
{
var p1,p2;
p1=login.paw.value;
p2=login.paww.value;
if(p1!=p2)
{alert("两次密码不一致,请确认密码");}
}
function checkcode()
{
var s;
s=1000+Math.floor(Math.random()*9000);
return s;
}
var num;
function scanfin()
{
var s;
s=document.getElementById("k");
if(parseInt(s.value)!=num)
alert("验证码输入错误,请重新输入!");
}
function product()
{
s=1000+Math.floor(Math.random()*9000);
num=s;
var v=document.getElementById("code");
v.innerHTML=num;
}
</script>
</head>
<body>
<table align="center" border="2" width="400" >
<form name="login" action="http://localhost:8080/LYX/Login.jsp">
<tr>
<td bgcolor="#FF6666" colspan="2" align=center><b>注册 </b></td>
</tr>
<tr bgcolor=#FFCCCC>
<td>用户名</td>
<td><input type="text" name="user"></td> <!-- 必须有value -->
</tr>
<tr bgcolor=#FFCCCC>
<td>学号</td>
<td><input type="text" name="usernode"></td>
</tr>
<tr bgcolor=#FFCCCC>
<td>密码</td>
<td><input type="password" name="paw"></td>
</tr>
<tr bgcolor=#FFCCCC>
<td>确认密码</td>
<td><input type="password" name="paww" onblur="check(this)"></td>
</tr>
<tr bgcolor=#FFCCCC>
<td>性别</td>
<td>
<input type="radio" name="sex" value="男" checked>男
<input type="radio" name="sex" value="女" >女
</td>
</tr>
<tr bgcolor=#FFCCCC><td>学院</td>
<td><select name="s1"><option value="信息学院" selected>信息学院</option>
<option value="经管学院">经管学院</option>
<option value="机电学院">机电学院</option>
<option value="交通学院">交通学院</option>
<option value="林学院">林学院</option>
<option value="理学院">理学院</option>
</select>
<select name="s2"><option value="计算机专业" selected>计算机专业</option>
<option value="软件专业">软件专业</option>
<option value="信管专业">信管专业</option>
<option value="园林专业">园林专业</option>
</select>
<select name="s3"><option value="1班" selected>1班</option>
<option value="2班">2班</option>
<option value="3班">3班</option>
<option value="4班">4班</option>
<option value="5班">5班</option>
<option value="6班">6班</option>
</select>
</td>
<tr bgcolor=#FFCCCC><td>爱好</td>
<td><input type="checkbox" name="hb" value="1">游泳
<input type="checkbox" name="hb" value="2">音乐
<input type="checkbox" name="hb" value="3">旅游
</td>
</tr>
<tr bgcolor=#FFCCCC><td>请提交自己的照片</td><td colspan="2"><input type="file" name="f1" /></td>
</tr>
<tr bgcolor=#FFCCCC><td>自我介绍:<td><textarea cols=25 rows=3 name="intr"></textarea></td>
</tr>
<tr bgcolor=#FFCCCC><td>验证码<td>
<span id="code" > <script> num=checkcode();
document.write(num);
</script>
</span><input type="text" name="yzm" size="10" id="k" onblur="scanfin()">
<input type="button" value="看不清楚" onclick="product()" >
<tr>
<td colspan="2" align="center"><input type="button" value="提交" onclick="submit()" />
<input type="reset" value="重置" />
</td>
</tr>
</form>
</table>
</body>
</html>

Login.jsp:


<%@page import="org.apache.tomcat.util.descriptor.web.LoginConfig"%>
<%@page import="org.apache.catalina.User"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

</head>
<body>
<%
String name=request.getParameter("user");
String usernode=request.getParameter("usernode");
String paw=request.getParameter("paw");
String sex=request.getParameter("sex");
String s1=request.getParameter("s1");
String s2=request.getParameter("s2");
String s3=request.getParameter("s3");
String[] hb=request.getParameterValues("hb");
String intr=request.getParameter("intr");


if(name.equals("user")){
out.print("该用户名已被注册"+"<br>");
out.print("用户名:"+name+"<br>");
out.print("学号:"+usernode+"<br>");
out.print("密码:"+paw+"<br>");
out.print("性别 :"+sex+"<br>");
out.print("学院: "+s1+"<br>");
out.print("专业: "+s2+"<br>");
out.print("班级: "+s3+"<br>");
out.print("爱好: ");
if (hb!=null)
//前端的使用者,如果没打勾的话
//request.getParameterValues("langtype")会接收到null值
{
for(int i=0;i<hb.length;i++)
{
if(Integer.parseInt(hb[i])==1)
{out.print("游泳 "); }//xy[i]为字符串1
if(Integer.parseInt(hb[i])==2)
{out.print("音乐 "); }//xy[i]为字符串1
if(Integer.parseInt(hb[i])==3)
{out.print("旅游 "); }//xy[i]为字符串1

}
}
out.print("<br>");
out.print("自我介绍: "+intr+"<br>");

}
else if(name.equals("admin")){ %>

<div align="center">欢迎你管理员!</div>

<% }
else{ %>
<div align="center">注册成功!</div>

<% }
%>

</body>

</html>

原文地址:https://www.cnblogs.com/wanghaoning/p/14143675.html