飞行的猪哼哼

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

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");
       Cookie cookie = new Cookie ("name",name);
       response.addCookie(cookie);
       response.sendRedirect("result.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>
     <%!
         String uname ;  
      %>
      <%
       Cookie[] cookies = request.getCookies();   
          for(Cookie cookie : cookies)
          {
        	  if(cookie.getName().equals("uname"))
        	  {
        		  uname = cookie.getValue();
        	  }
          }
      %>
    <form action="check.jsp" method="post" >
          用户名:<input type="text" name="uname" value="<%=(uname==null?"":uname)%>">  <br/>
           密码:<input type="password" name="upwd"><br/>  
           <input type="submit"  value="登录"><br/>  
     </form>
</body>
</html>

result.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>
欢迎进入!!!!!!!!!
</body>
</html>

在这里插入图片描述

posted on 2019-05-28 19:40  飞行的猪哼哼  阅读(24)  评论(0)    收藏  举报