request,session,application 取值方法

JSP:


<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 
<%@ taglib uri="/struts-tags"  prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
   
    <title>My JSP 'index.jsp' starting page</title>
 
  </head>
  
  <body>
     第一种方法<br>
        request :<s:property value="#request.msg"/><br>
        session :<s:property value="#session.msg"/><br>
        application :<s:property value="#application.msg"/><br>
        第二种方法<br>
         request :${requestScope.msg}<br>
        session :${sessionScope.msg }<br>
        application :${requestScope.msg }<br>
  </body>
</html>

action:

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


public class OGNLAction extends ActionSupport {
    private HttpServletRequest req;
    
    @Override
    public String execute() throws Exception {
          ActionContext context = ActionContext.getContext();
          Map request = (Map) context.get("request");
          Map session = context.getSession();
          Map  appication = context.getApplication();
          
          request.put("msg", "requestMessage");
          session.put("msg","SessionMessage");
          appication.put("msg", "applitionMessage");
          return SUCCESS;
    }
    
}

你可能感兴趣的:(request,session,application 取值方法)