第四周作业(登录验证码)

register.jsp

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 
 3 
 4 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 5 <html>
 6 <head>
 7 
 8 <title></title>
 9 
10 
11 </head>
12 
13 <body>
14 
15      <form action="display.jsp" method="post"><br>
16      账号:
17     <input type="text" name="zh"><br>
18      密码:
19      <input type="password" name="mm"><br>
20      验证码:
21     <input type="text" name="yz">
22      <img id="yzm" src="image/a.jpg"/>换一张<br>
23      <input type="submit" value="登录" name="dl">
24 
25     </form>
26 </body>
27 </html>

display.jsp

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <html>
 3 
 4 <body>
 5 <%
 6     //获取登录的用户名
 7 String name= request.getParameter("zh");
 8 //获取登陆密码
 9 String pwd= request.getParameter("mm");
10 //判断
11 if(name.equals("zs")&& pwd.equals("123"))
12 //转发到OK界面
13 request.getRequestDispatcher("ok.jsp").forward(request,response);
14 else 
15 //转发到no界面
16 request.getRequestDispatcher("no.jsp").forward(request,response);
17 %>
18 </body>
19 </html>

ok.jsp

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 <%
 3     request.setCharacterEncoding("utf-8");
 4     String name = request.getParameter("zh");
 5     String pwd = request.getParameter("mm");
 6 
 7 %>
 8 
 9 <% request.setCharacterEncoding("utf-8");%>
10 <h1>登陆成功</h1>

no.jsp

 1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 2 
 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 4 <html>
 5 <head>
 6 
 7 <title>My JSP 'dologin.jsp' starting page</title>
 8 
 9 <meta http-equiv="pragma" content="no-cache">
10 <meta http-equiv="cache-control" content="no-cache">
11 <meta http-equiv="expires" content="0">
12 <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
13 <meta http-equiv="description" content="This is my page">
14 <!--
15     <link rel="stylesheet" type="text/css" href="styles.css">
16     -->
17 
18 </head>
19 
20 <body>
21     <% request.setCharacterEncoding("utf-8");%>
22     <h1 style="color:red">登陆失败</h1>

 

 

 

 

 

 

 

posted @ 2021-03-28 17:24  冰封~  阅读(47)  评论(0编辑  收藏  举报