码迷,mamicode.com
首页 > 其他好文 > 详细

05第六周

时间:2020-04-11 20:45:08      阅读:64      评论:0      收藏:0      [点我收藏+]

标签:str   post   中文   eve   attr   sub   http   set   word   

<%@ 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">
</style>
<script type="text/javascript">
    function mycheck(){
    if(form1.userName.value==""){
    alert("用户名不能为空,请输入用户名");
    form1.userName.focuse();
    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>
</head>
<body>
   <form action="loginCheck.jsp" name="form1" method="post">
   用户名:<input type="text" name="userName" size="16"><br>&nbsp;&nbsp;&nbsp;码:
   <input type="password" name="password" size="18"><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 style="height:20px;weight:20px" src="num/<%=intmethod1 %>.png">
   <img style="height:20px;weight:20px" src="num/<%=intmethod2 %>.png">
   <img style="height:20px;weight:20px" src="num/<%=intmethod3 %>.png">
   <img style="height:20px;weight:20px" src="num/<%=intmethod4 %>.png">
   <br>
   <input type="submit" name="submit1" value="登录" onClick="mycheck()">
   &nbsp;
   <input type="reset" value="重置">
   </form>
    
     <br>
  </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>
<% 
//设置请求的编码,用于解决中文乱码问题
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("l")&&(password.equals("1"))){
//把用户名到session中
session.setAttribute("userName",name);
response.sendRedirect(" main.jsp"); 
}else{
response.sendRedirect("login.jsp"); 
}else{
response.sendRedirect("loginjsp");
}
%>
</body>

</html>

技术图片技术图片

05第六周

标签:str   post   中文   eve   attr   sub   http   set   word   

原文地址:https://www.cnblogs.com/1014040868lyn/p/12681874.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!