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参数,后台就会打印参数值

  • 相关阅读:
    screen:多重视窗管理程序
    tcpdump、nc网络工具使用
    Linux下查看系统版本号信息的方法
    python列表模拟堆栈和队列
    Linux Service and Security
    day2 列表
    Python常用方法
    Nginx1.6.0+MySQL5.6.19+PHP5.5.14(centos)
    LINUX Mysql5.6.19 安装
    python+django+pycharm 环境配置 (window7)
  • 原文地址:https://www.cnblogs.com/hujiapeng/p/4668386.html
Copyright © 2011-2022 走看看