struts2 request问题Java codepublic class CreateTableSpaceAction extends ActionSupport{private stati
struts2 request问题
Java codepublic class CreateTableSpaceAction extends ActionSupport{ private static final long serialVersionUID = 1L; private HttpServletRequest request; public HttpServletRequest getRequest() { return request; } public void setRequest(HttpServletRequest request) { this.request = request; } @Override public String execute() throws Exception{ System.out.println("======CreateTableSpaceAction====="); //这里报空指针 String spaceName = (String) request.getAttribute("spaceName");//34行 System.out.println("spaceName:"+spaceName); String spaceSize = request.getParameter("spaceSize"); String spacePath = request.getParameter("spacePath"); SysUserPOJO sysUserPOJO = getsysUser(request); InitSysDAO initSysDAO = new InitSysDAO();
严重: Servlet.service() for servlet default threw exception
java.lang.NullPointerException
at com.asideal.action.sysInit.CreateTableSpaceAction.execute(CreateTableSpaceAction.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[解决办法]你在提交时有没有传spaceName这个参数
[解决办法]表单提交问题,看参数名对应上了嘛,还有struts2最好不要这么传值,直接get/set接值比较好
[解决办法]我记得request有其他方法可以取,你那个申明get set方法应该取不到
[解决办法]request null? 还是request.getAttribute("spaceName") null 可以用输出先调试的看下
[解决办法]public class CreateTableSpaceAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private String spaceName;
public String getSpaceName(){
return spaceName;
};
public void setSpaceName(spaceName){
this.spaceName=spaceName;
}
private HttpServletRequest request;
public HttpServletRequest getRequest() {
return request;
}
public void setRequest(HttpServletRequest request) {
this.request = request;
}
//如果是用post的话这样就行了,如果是get的话就要传spaceName=?(?号是你要传的值)
@Override
public String execute() throws Exception{
System.out.println("======CreateTableSpaceAction=====");
System.out.println("spaceName:"+spaceName);
String spaceSize = request.getParameter("spaceSize");
String spacePath = request.getParameter("spacePath");
SysUserPOJO sysUserPOJO = getsysUser(request);
InitSysDAO initSysDAO = new InitSysDAO();
[解决办法]request那样能取到吗?试试这样:httpservletrequest request=servletactionsupport.getrequest();
[解决办法]拜托,request.getParameter("键名")
[解决办法]request.getAttribute("spaceName");
改为 request.getParameter("spaceName");
试试
[解决办法]boolean isExist = spaceIsExist(initSysDAO,spaceName,jdbc_ora_username,jdbc_ora_password
这句话抛出的异常 ? 那看下这个方法吧
[解决办法]
既然spaceName定义成属性,并且提供getter setter方法,那么可以直接用。不需要request.getParameter().还有总是感觉你那request是null。最好用ServletActionContext.getRequest()来获取下!
[解决办法]
String spaceName = (String) request.getAttribute("spaceName");//34行
这个改一下:
Java codeString spaceName = "";if(request.getAttribute("spaceName") != null && !"".equals(request.getAttribute("spaceName") [code=Java]