JSP 05课(第六周作业)
<%@ 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> <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"> --> <style type="test/css"> body{font-size:16px;} </style> <script type="text/javascript"> function mycheck(){ //检查用户名 if(form1.userName.value==""){ alert("请输入用户名"); form1.userName.focus(); return; } //判断密码 if(form1.password.value==""){ alert("请输入密码"); form1.password.focue(); return; } //判断验证码 if(form1.validationCode.value==""){ alert("请输入验证码"); form1.validationCode.foucs(); return; } //判断验证码是否有误 if(form1.validationCode.value!=form1.validationcode1.value){ alert("请输入正确的验证码"); form1.validationCode.foucs(); return; } form1.submit(); } </script> </head> <body bgcolor="pink"> <form action="loginCheck.jsp" name="form1" method="post" style="margin-top:15px"> 用户:<input type="text" name="userName" size="18"> <br>密码:<input type="password" name="password" size="18" style="margin-top:15px"> <br>验证:<input type="text" name="validationCode" onKeyDown="if(event.keyCode==13){form1.submit.focus();}" size="6" style="margin-top:15px"> <% int intmethod1=(int)((((Math.random())*11))-1); int intmethod2=(int)((((Math.random())*11))-1); int intmethod3=(int)((((Math.random())*11))-1); int intmethod4=(int)((((Math.random())*11))-1); //连接随机数 String intsum=intmethod1+""+intmethod2+intmethod3+intmethod4; %> <!--设置隐藏域,验证比较时使用--> <div style="margin-top:15px"> <input type="hidden" name="validationCode1" value="<%=intsum%>"> <img src="image/<%=intmethod1%>.gif"> <img src="image/<%=intmethod2%>.gif"> <img src="image/<%=intmethod3%>.gif"> <img src="image/<%=intmethod4%>.gif"> </div> <br> <input type="submit" name="submit1" value="登录" onClick="mycheck()" style="margin-top:15px"> <input type="reset" value="重置"> </form> </body> </html>
<%@ 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> <base href="<%=basePath%>"> <title>My JSP 'loginCheck.jsp' starting page</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"> --> </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("shenme")&&(password.equals("123456"))){ session.setAttribute("userName", name); response.sendRedirect("main.jsp"); }else{ response.sendRedirect("login.jsp"); } }else{ response.sendRedirect("login.jsp"); } %> <body> This is my JSP page. <br> </body> </html>
<%@ 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> <base href="<%=basePath%>"> <title>My JSP 'main.jsp' starting page</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"> --> </head> <body bgcolor="pink"> <body> <% String name=(String)session.getAttribute("userName"); %> 您好<%=name %>,欢迎访问<br> <a href="exit.jsp">退出系统</a> <br> </body> </html>
<%@ 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> <base href="<%=basePath%>"> <title>My JSP 'exit.jsp' starting page</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"> --> </head> <body bgcolor="pink"> <body> <% session.invalidate(); response.sendRedirect("login.jsp"); %> </body> </html>