<%@ 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> <style type="text/css"> body { background-color: pink; } form { margin-top: 100px; margin-left: 100px; } img{ height-line:20px; height:20px; width:20px; } </style> <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.submit1(); } </script> <base href="<%=basePath%>"> <title>My JSP 'index.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> <form action="LoginCheck.jsp" method="get"> 用 户 名:<input type="text" name="userName" size="18"><br><br> 密 码:<input type="password" name="password" size="18"> <br><br> 验 证 码:<input type="text" name="validationCode" onKeyDown="if(event.keyCode==13){form1.submit.focus();}" size="6"> <% 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; %> <!-- 设置隐藏域,验证比较时使用--> <input type="hidden" name="validationCode1" value="<%=intsum%>"> <!-- 将图片名称与得到的随机数相同的图片显示在页面上 --> <img src="./img/<%=intmethod1%>.jpg"> <img src="./img/<%=intmethod2%>.jpg"> <img src="./img/<%=intmethod3%>.jpg"> <img src="./img/<%=intmethod4%>.jpg"><br><br> <input type="submit" name="submit1" value="登录" onClick="mycheck()"> <input type="reset" value="重置"> </form> </form> </body> </html>
浙公网安备 33010602011771号