struts2前后台传值汇总-(1)ActionContext-map格式

阅读更多

后台调用ActionContext中的getObject(),getSession(),getApplication() 获取request,session,application.

 

package struts.test.action;

import java.sql.SQLException;
import java.util.Map;

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

/**
 * 登录练习
 * @author zk
 *
 */
//public class LoginAction implements Action {
public class LoginAction extends ActionSupport {

	//获取request对象
	ActionContext context;
	Map request1;
	Map session1;
	Map application1;
	
	
	@Override
	public String execute() throws Exception {
					
			context = ActionContext.getContext();
			request1 = (Map)context.get("request");
			session1 = context.getSession();
			application1 = context.getApplication();
			
			request1.put("req", "request1属性");
			session1.put("ses", "session1属性");
			application1.put("app", "application1属性");
			
			
			
			
			return SUCCESS;
	}

	
}

 

 

 

前台2种方式获取(EL表达式和控制反转IOC)

<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
%>



	

adminSuc

管理员页面

requset属性接受:
session属性接受:
application属性接受:

=============================

另外一种获取方法 :


requset属性接受:${requestScope.req}
session属性接受:${sessionScope.ses}
application属性接受:${applicationScope.app}


返回

 

 

  • struts2前后台传值汇总-(1)ActionContext-map格式_第1张图片
  • 大小: 278 KB
  • 查看图片附件

你可能感兴趣的:(ActionContext)