struts2 Action中获取request, response对象的 几种 方法

xiaoxiao2026-03-14  8

struts2 Action中获取request, response对象的方法 第一种方法: ActionContext ctx = ActionContext.getContext(); HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST); HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE); //ServletActionContext.APPLICATION; //ServletActionContext.SESSION; //ServletActionContext.PAGE_CONTEXT; 第二种方法: 实现 ServletRequestAware public class TestAction implements ServletRequestAware{ /**---*/ public void setServletRequest(HttpServletRequest request) { // 要复写这个方法 request.setAttribute("key","value"); }} 第三种:更简单的一种。。 HttpServletRequest request = ServletActionContext.getRequest();
转载请注明原文地址: https://www.6miu.com/read-5045888.html

最新回复(0)