在我的Action的execute()函数中, public String execute(){ System.out.println("action"); if(getUser().equals("liu")&&getPassword().equals("shilei")){ ActionContext.getContext().getSession().put("user", getUser()); Cookie cookie=new Cookie("user",user); cookie.setMaxAge(60*60); response.addCookie(cookie);//就是这里出错了 return SUCCESS; } return ERROR; } 执行后的结果 java.lang.NullPointerException action.LoginAction.execute(LoginAction.java:38) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) java.lang.reflect.Method.invoke(Method.java:597) com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:440) com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:279) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242) response我是在Action中声明的一个private HttpServletResponse response;
1 回答
收到一只叮咚
TA贡献1821条经验 获得超4个赞
我记得structs2要实现implements
ServletResponseAware
接口重写
@Override
public
void
setServletResponse(HttpServletResponse
arg0)
{
this.response
=
arg0;
}
private
HttpServletResponse
response;
//添加set方法
//这样就可以获得response了
不会出现空值了
- 1 回答
- 0 关注
- 92 浏览
添加回答
举报
0/150
提交
取消