jsp第五次作业
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录页面</title>
<style type="text/css">
body{font-size: 16px}
</style>
</head>
<body bgcolor="pink">
<form action="loginCheck.jsp" name="form1" method="post">
用户名:<input type="text" name="userName" size="16">
<br>密 码:<input type="password" name="password" size="18">
<br>
验证码:<input type="text" name="validationCode"
onkeyDown="if(event.keyCode==13){form1.submit.focus();}" size=6>
<!-- 按下回车键的值-->
<%
int code1 = (int)(((Math.random())*11)-1);
int code2 = (int)(((Math.random())*11)-1);
int code3 = (int)(((Math.random())*11)-1);
int code4 = (int)(((Math.random())*11)-1);
//将的到的随机数进行连接
String intsum = ""+code1+code2+code3+code4;
%>
<!--设置隐藏域验证比较时使用 -->
<input type="hidden" name="validationCode1" value="<%=intsum%>">
<input type="text" value="<%=intsum%>" readonly="true" size=2>
<br>
<input type="button" name="submit1" value="登录" onclick="mycheck()">
<input type="reset" value="刷新">
</form>
</body>
<script type="text/javascript">
function mycheck() {
if(form1.userName.value==""){
alert("用户名不能为空请输入用户名!");
form1.userName.focus();
return;
}
if(form1.password.value==""){
alert("密码不能为空请输入密码!");
form1.password.focus();
return;
}
if(form1.validationCode.value==""){
alert("验证码不能为空请输入验证码!");
form1.validationCode.focus();
return;
}
//判断验证码是否正确
if(form1.validationCode.value!=form1.validationCode1.value){
alert("请输入正确的验证码!!");
form1.validationCode.focus();
return;
}
form1.submit();
}
</script>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>处理登录页面数据</title>
</head>
<body bgcolor="pink">
<%
//设置请求的编码,永远解决中文乱码问题
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("userName");
String password = request.getParameter("password");
if(request.getParameter("validationCode1").equals(request.getParameter("validationCode"))){
if(name.equals("xinxin")&&password.equals("jingjing")){
session.setAttribute("userName", name);
response.sendRedirect("main.jsp");
}else{
response.sendRedirect("Login.jsp");
}
}else{
response.sendRedirect("Login.jsp");
}
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>系统主页面</title>
</head>
<body bgcolor="pink">
<%
String name = (String)session.getAttribute("userName");
%>
您好<%=name %>,欢迎访问<br>
<a href="exit.jsp">[退出系统]</a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>退出系统</title>
</head>
<body>
<%
session.invalidate();
response.sendRedirect("Login.jsp");
%>
</body>
</html>







浙公网安备 33010602011771号