日期:2014-05-18  浏览次数:20718 次

用struts的upload上传文件时出现了异常...请大家帮我看看哪里有问题.
jsp里代码:<html:file property="myPic" size="40" onchange="javascript:PreviewImg(this);"></html:file>

form里的代码:private FormFile myPic;

public FormFile getMyPic() {
return myPic;
}

public void setMyPic(FormFile myPic) {
this.myPic = myPic;
}

action 里代码:FormFile file = humanInfoForm.getMyPic();
  System.out.println(file.getFileName());
InputStream stream = file.getInputStream();
String path = this.getServlet().getServletContext().getRealPath("/upload");
System.out.println(path);
OutputStream outStream = new FileOutputStream(path + "/"+ file.getFileName());
int bytesRead = 0;
byte[] by = new byte[8196];
while ((bytesRead = stream.read(by, 0, 8192)) != -1) {
outStream.write(by, 0, bytesRead);
}
outStream.close();
stream.close();
}
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("exception===================");
}
报了java.lang.NullPointerException 这个异常..大家帮我看看哪里错了...代码基本是拷的我一个同学的,他的没问题,我的就出这个异常了.


------解决方案--------------------
光是这个java.lang.NullPointerException 是看不出错误的,你把具体控制台打印的错误发上来帮你看一下吧...
------解决方案--------------------
自己设个断点调试就出来了