• JavaWeb——Session的前后端交互(简洁代码)


    JAVA程序代码:

    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import java.io.IOException;
    
    @WebServlet("/sessionDemo")
    public class SessionDemo extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException  {
            //使用session共享数据
            //1.获取session
            HttpSession session = request.getSession();
            //2.存储数据
            session.setAttribute("msg","木心小白菜!");
        }
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doPost(request, response);
        }
    }

    JS程序代码:

    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <html>
    <head>
        <title>标题</title>
    </head>
    <body>
        <h1><%=request.getSession().getAttribute("msg")%>,欢迎您</h1>
    </body>
    </html>
  • 相关阅读:
    Python多线程join的用法
    Python多线程互斥锁
    python Queue模块
    精度计算————乘法(大数乘小数)
    精度计算——大数阶乘
    python埃式筛法求素数
    Scala io操作
    scala io,ubuntu常见配置
    大数据之scala高级语法学习
    大数据之scala基本语法学习
  • 原文地址:https://www.cnblogs.com/mxxbc/p/14039025.html
Copyright © 2020-2023  润新知