使用response对象模拟用户登录后的跳转
login.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> * { padding: 0; margin: 0; } .title { font-size: 30px; font-weight: 700; text-align: center; } .body { height: 110px; width: 400px; margin: 50px auto; text-align: center; } .user, .passwd { margin: auto; width: 60%; height: 35px; } .user .left, .passwd .left { float: left; margin-right: 10px; } .user .right, .passwd .right{ float: left; } .foot { position: relative; margin: auto; width: 100%; height: 20%; } .foot .sub { position: absolute; left: 125px; } .foot .reset { position: absolute; right: 115px; } .sub button, .reset button { width: 70px; height: 40px; }
</style> </head> <body> <form action="login.jsp" method="post" class="main"> <div class="title">用户登录</div> <div class="body"> <div class="user"> <div class="left">用户:</div> <div class="right"> <input type="text" name="user"> </div> </div> <div class="passwd"> <div class="left">密码:</div> <div class="right"> <input type="password" name="passwd"> </div> </div> <div class="foot"> <div class="sub"> <button type="submit" name="submit">登录</button> </div> <div class="reset"> <button type="reset" name="reset">重置</button> </div> </div> </div> </form>
</body> </html>
|
自己简单的写的,不太美观 因为没有原型图
login.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| <%-- Created by IntelliJ IDEA. User: DELL Date: 2022/9/16 Time: 23:58 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> <script> window.onload=function(){ var t=4; var span = document.querySelector("span"); var timer = setInterval(function(){ if(t===0) { clearInterval(timer); } else { span.innerHTML=t; t--; }
},1000) } </script> </head> <body> <% request.setCharacterEncoding("UTF-8"); String user = request.getParameter("user"); String passwd = request.getParameter("passwd"); if(user.length()==0 || passwd.length()==0){ out.println("<h3>请正确输入,<span>5</span>秒后返回登录<a href='login.html'>登录页面</a></h3>"); response.setHeader("Refresh","5;url=login.html"); } else if(user.equals("kittates")&&passwd.equals("kittates") && user.length()!=0 &&passwd.length()!=0) { response.sendRedirect("success.jsp?name="+user); }
else { out.println("<h3>用户名或密码错误,<span>5</span>秒后返回登录<a href='login.html'>登录页面</a></h3>"); response.setHeader("Refresh","5;url=login.html"); } %> </body> </html>
|
简简单单写了一个倒计时功能
success.jsp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <%-- Created by IntelliJ IDEA. User: DELL Date: 2022/9/17 Time: 0:10 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h2>welcome <%= request.getParameter("name")%>!</h2> </body> </html>
|
体验
总体来说还算很好,只是在调试hexo的时候浪费了一部分事件,从下午六点多到现在这个点儿,还不算太困:),换做其他天,早就…
明天继续学!