我真的这样做Java + Spring:如果我有没有HttpRequest的路径,我可以上传文件吗?
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command, BindException errors)
throws Exception {
MultipartFile multipartFile = null;
File destFile = new File(
"/home/stas/eclipse/" + request.getParameter("fileName"));
multipartFile.transferTo(destFile);
但我有例外
27.03.2012 20:39:45 org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [springapp] in context with
path [/springapp] threw exception [Request processing failed;
nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException
你没有指定'multipartFile'任何东西。你怎么能指望它不扔NPE? – adarshr 2012-03-28 11:41:03