session

1,session保存在操作方便,保存在服务器,同样需要setCharacterSet(“UTF—8”)

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ page import="kooing.People" %>
<% 
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    People people[]={new People("huanggabin","b",22)
                    ,new People("黄嘎兵","huanggabin",22)
                    ,new People("dsf","famale",22)};
    String message="";
    if(request.getMethod().equals("POST")){
        for(People personA:people){
            if(personA.getName().equals(request.getParameter("name"))&&
                    personA.getPassword().equals(request.getParameter("password"))){
                session.setAttribute("person",personA);
                response.sendRedirect(request.getContextPath()+"/welcom.jsp");
                return;
            }
        }
    }
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <form action="session.jsp" method="post">
            账号:<input type="text" name="name"><br />
            密码: <input type="text" name="password"><br />
            <input type="submit" value="okokok">huan
        </form>
     </body>
</html>
View Code
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<jsp:directive.page import="java.util.*"/>
<jsp:directive.page import="kooing.People"/>
<%
    People people=(People)session.getAttribute("person");
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
           你的账号:<%=people.getName() %><br/>
           你的密码:<%=people.getName() %><br/>
           你的年龄:<%=people.getAge() %>
     </body>
</html>
View Code

 

posted on 2017-02-28 09:04  Kooing  阅读(199)  评论(0编辑  收藏  举报

导航