最终效果:
实现目的:1.可以自己选择身份登入,左上角显示是第几个访问访客
2.可以选择是否记住密码
3.个人信息为超链接,点击即跳转到个人信息详细界面
4.点击登录按钮或者未输入账号密码而移开鼠标,会网站提醒即非空验证
5.所输入的账号和密码需要由数据库的数据支持,若无数据库的数据匹配上同样也会 进行报错
代码:login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script>
<!--
function isValid()
{if (frmlogin.id.value == "")
{alert("您必须完成账号的的输入!");
document.frmlogin.elements(0).focus();
return false;}
else
if (frmlogin.password.value == "")
{alert("您必须完成密码的输入!");
document.frmlogin.elements(1).focus();
return false;}
else
frmlogin.submit();
}
function lost()
{if (frmlogin.id.value == "")
{document.getElementById("ids").innerHTML="请输入账号!!"}
else
if(frmlogin.password.value == "")
{document.getElementById("pas").innerHTML="请输入密码!!"}
}
-->
</script>
<base href="<%=basePath%>">
<title>用户登录</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<%if(session.isNew())
{Integer number = (Integer)application.getAttribute("count");
if(number == null){
number = new Integer(1);
application.setAttribute("count", number);}
else
{number = new Integer(number.intValue()+1);
application.setAttribute("count", number);
}}
request.setCharacterEncoding("utf-8");
String wang=request.getParameter("wang");
if(wang != null && wang.equals("0"))
{
out.print("<p style='color: red;text-align: center;'>用户名或密码错误!!请检查并重新输入!!</p>");
}%>
<%Cookie[] cookie=request.getCookies();
String username="";
String password="";
if(cookie != null && cookie.length>0)
{
for(Cookie c:cookie){
if(c.getName().equals("username")){
username=c.getValue();
}
if(c.getName().equals("password")){
password=c.getValue();
}
}
}%>
</head>
<body bgcolor="#FFFFF0">
<p><font style="color: blue" size="5">您是第<%=(Integer)application.getAttribute("count")%>位访客</font></p>
<center><b><font color="#FFD700" size="7" face="华文行楷" >学生课绩管理系统</font></b></center>
<form action="loginforword.jsp" method="post" name="frmlogin">
<table width="50%" height="200" border=1 bgcolor="#E6E6FA" align="center">
<tr>
<td align="right">
<font color="#32CD32" size="5" face="华文行楷">用户选择</font>
</td>
<td align="left">
<input name="kind" type="radio" value="student" checked>
<font color="#32CD32" size="5" face="华文行楷">学生</font>
<input type="radio" name="kind" value="teacher">
<font color="#32CD32" size="5" face="华文行楷">教师</font>
<input type="radio" name="kind" value="admin">
<font color="#32CD32" size="5" face="华文行楷">管理员</font>
</td></tr>
<tr>
<td align="right">
<font color="#32CD32" size="5" face="华文行楷">登录名</font></td>
<td align="left"><input name="id" type="text" maxlength="20" value="<%=username%>"/><span style="color: red" id="ids"></span></td>
</tr>
<tr>
<td align="right" >
<font color="#32CD32" size="5" face="华文行楷">密码</font></td>
<td><input name="password" type="password" maxlength="8" onBlur="lost()" value="<%=password%>"/><span style="color: red" id="pas"></span></td>
</tr>
<tr><td colspan="2" align="center" ><input type="checkbox" name="isusecookie"/>是否记住账号密码</td></tr>
<tr><td colspan="2" align="center">
<input type="button" name="Submit" value="登录" onclick="isValid()">
</td></tr>
</table></form>
<center><b><font color="#99FF33" size="2" >版权所有©:<a href="names.jsp">个人信息</a></font></b></center>
</body>
</html>