我有一个jsp文件UploadCoupon.jsp
如下图片上传
<form:form commandName="uploadcoupon" enctype="multipart/form-data" method="POST">
<form:input type="file" path="couponImage" class="file_1 required"/><br/>
<form:errors path="couponImage" cssClass="error" style="color:red" /><br/>
<input id="uploadCouponButton" type="submit" value="" class="form-submit" />
</form:form>
Bean 类Coupon.java
如下所示
public class Coupon {
MultipartFile couponImage;
public MultipartFile getCouponImage() {
return couponImage;
}
public void setCouponImage(MultipartFile couponImage) {
this.couponImage = couponImage;
}
}
Dispatcher servlet 具有以下代码
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
控制器UploadCoupon.java
如下
public class UploadCoupon extends SimpleFormController
{
public UploadCoupon()
{
setCommandClass(Coupon.class);
setCommandName("uploadcoupon");
}
@Override
protected ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response,
Object command,
BindException errors) throws Exception {
try {
Coupon coupon = (Coupon)command;
MultipartFile multipartFile = coupon.getCouponImage();
// image type of file processing...
} catch (Exception e) {
System.out.println("Exception -"+e.getMessage());
}
mv = new ModelAndView(new RedirectView("UploadCoupon.htm");
return mv;
}
}
此代码在本地主机上的 Glassfish 服务器上部署时工作正常,但是当我在 Glassfish 服务器上的远程主机上部署它时,multipartFile 对象为 null 并且发生 NullPointerException。我不明白在远程主机上部署它有什么问题?