zoukankan      html  css  js  c++  java
  • java中request,application,session三个域及参数简单示例

    直接上代码:

    java代码:

    public class HelloAction implements Action {
        @Override
        public String execute() throws Exception {
            Map<String, Object> requestScope = (Map<String, Object>) ActionContext.getContext().get("request");
            Map<String, Object> sessionScope = ActionContext.getContext().getSession();
            Map<String, Object> applicationScope = ActionContext.getContext().getApplication();
            Map<String, Object> params = ActionContext.getContext().getParameters();
            requestScope.put("name", "request");
            sessionScope.put("name", "session");
            applicationScope.put("name", "application");
            String[] strs = (String[]) params.get("name");
            System.out.println(Arrays.toString(strs));
            return SUCCESS;
        }
    }

    jsp页面

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    ${requestScope.name}<br/>
    ${sessionScope.name}<br/>
    ${applicationScope.name}<br/>
    </body>
    </html>

    访问的时候追加name参数,后台就会打印参数值

  • 相关阅读:
    竞赛题解
    学习笔记
    竞赛题解
    学习笔记
    竞赛题解
    竞赛题解
    竞赛题解
    「链接」原博客链接
    「杂录」THUWC 2020 游记
    「杂录」CSP-S 2019 爆炸记&题解
  • 原文地址:https://www.cnblogs.com/hujiapeng/p/4668386.html
Copyright © 2011-2022 走看看