zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    C++实现base64编解码
    使用matplotlib绘制3D函数图像
    C++分治策略实现快速排序
    C++分治策略实现二分搜索
    C++生成随机数
    eBay 表结构
    mysql 流程函数
    无限极分类
    PHP 导出 Excell
    js
  • 原文地址:https://www.cnblogs.com/mxxbc/p/14039025.html
Copyright © 2011-2022 走看看