ServletActionContext.getResponse()的报错原因

J2EE 码拜 7年前 (2017-04-21) 2304次浏览
HttpServletResponse response = ServletActionContext.getResponse();
在引入了struts2框架后为什么这一段代码ServletActionContext.getResponse(); 报错
报错信息为Cannot make a static reference to the non-static method getResponse() from the type ServletActionContext
求指导答
解决方案

10

说明当前你的这个类里引用的ServletActionContext ,不是org.apache.struts2.ServletActionContext,你看看你的类的imports

30

先获得一个ServletActionContext实例  ,然后再用实例的方法访问
非静态方法,需要用具体对象(实例)调用此方法

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明ServletActionContext.getResponse()的报错原因
喜欢 (0)
[1034331897@qq.com]
分享 (0)