一个简单的session传值学习

a.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form method="post" action="b.jsp">
    <input type="text" id="name" name="name">
    <input type="submit">
</form>
</body>
</html>

b.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    //解决乱码问题
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");

    String name = request.getParameter("name");
    System.out.println(name);
    session.setAttribute("flag",name);
    response.sendRedirect("c.jsp");
%>

c.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    Object name = session.getAttribute("flag").toString();
%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%=name%>
</body>
</html>

 

posted @ 2021-05-20 21:14  Arisf  阅读(78)  评论(0编辑  收藏  举报