我有一個JSP文件UploadCoupon.jsp
圖像上傳問題在文件上傳 - 值爲NULL,當遠程主機服務器上部署,但它工作正常本地主機服務器上
<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;
}
}
分派器servlet有以下代碼
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>
控制器UploadCoupon.java
是在本地主機上GlassFish服務器上部署時,按如下
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服務器multipartFile對象遠程主機上部署它是空和空指針異常發生。我無法理解在遠程主機上部署它有什麼問題?
感謝您的解決方案,我已經嘗試過,但仍然無法正常工作。我仍在等待一些解決方案。 –