飞行的猪哼哼

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

check.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
      <%
         request.setCharacterEncoding("utf-8");
       String name = request.getParameter("uname");
       String pwd = request.getParameter("upwd");
       if(name.equals("zs")&&pwd.equals("abc"))
       {
    	   session.setAttribute("uname",name);
    	   session.setAttribute("upwd",pwd);
    	   //只有登录成功session中才有人物信息。
    	   request.getRequestDispatcher("welcome.jsp").forward(request, response);
       }
       else
       {
    	   response.sendRedirect("login.jsp");
       }
      %>
</body>
</html>

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
     <form action="check.jsp" >
          用户名:<input type="text" name="uname"><br/>
           密码:<input type="password" name="upwd"><br/>  
           <input type="submit"  value="登录"><br/>  
     </form>
</body>
</html>

welcome.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
欢迎你:
      <%
          String name =(String) session.getAttribute("uname");
          out.print(name);
      %>
</body>
</html>

在这里插入图片描述

posted on 2019-05-28 20:36  飞行的猪哼哼  阅读(23)  评论(0)    收藏  举报