第一种:
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
第二种:
//实现类
implements RequestAware,SessionAware
//定义属性
private Map request;
private Map session;
//Set方法
public void setRequest(Map request) {
this.request = request;
}
public void setSession(Map session) {
this.session = session;
}
注意:两种方式各自往作用域中存取值的方法也是不一样的,且两者存放的值并不会共享;
另:也可通过ActionContext获取
//Java类中某ajax访问常用。
public static JSONObject service(JSONObject params, ActionContext context) {
HttpServletRequest req = (HttpServletRequest)context.get(ActionContext.REQUEST);
HttpServletResponse resp = (HttpServletResponse)context.get(ActionContext.RESPONSE);
}
本文转自 艺晨光 51CTO博客,原文链接:http://blog.51cto.com/ycgit/1619103,如需转载请自行联系原作者