为什么Struts2的Action中获取ServletActionContext.getPageContext()==null

package com.InteriorDesign.action;

import javax.servlet.ServletConfig;
import javax.servlet.jsp.PageContext;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
@Component("forwardAction")
public class ForwardAction extends ActionSupport {

private Logger logger=Logger.getLogger(ForwardAction.class);

public String execute(){
logger.info("============");

logger.info(ServletActionContext.getResponse()==null);

logger.info(ServletActionContext.getPageContext()==null);

logger.info(ServletActionContext.getPageContext().getServletConfig()==null);

return "success";
}

}

请问如何才能正常获取PageContext对象而不为空呢?

你没有继承struts2默认的包,就没有使用到struts2的默认拦截器,这些拦截器负责拦截参数,容器对象等等初始化内容,所以你这里获取不到任何容器里面的东西追问

ServletActionContext.getResponse() 这个是有值非空的
而只是ServletActionContext.getPageContext()==null

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-05-11
用下面:
ActionContext.getContext()
相似回答