主题: 本地上传没有问题 但是服务器上有时上传成功有时失败 失败提示错误如下 代码已粘贴
作者: 晴天雨日, 发布日期: 2014-08-21 08:10:53, 浏览数: 3112

报错提示错误329行是红色那行请各位大神帮忙看看 折腾了好几天了

public String uploadCompressImage(HttpServletRequest request,

HttpServletResponse response, PersistenceSession persistenceSession)
throws Exception {
// 文件保存目录路径
String savePath = Config.getInstance().getProductImageDir();

// 文件保存目录URL
String saveUrl = Config.getInstance().getProductImageUrl();
String imageWidth = Config.getInstance().getImageWidth();
String imageHeight = Config.getInstance().getImageHeight();
response.setContentType("text/html; charset=UTF-8");

if (!ServletFileUpload.isMultipartContent(request)) {
response.getWriter().write("请选择图片");
return null;
}
// 创建文件夹
File saveDirFile = new File(savePath);
if (!saveDirFile.exists()) {
saveDirFile.mkdirs();
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String ymd = sdf.format(new Date());
savePath += ymd + "/";
saveUrl += ymd + "/";
File dirFile = new File(savePath);
if (!dirFile.exists()) {
dirFile.mkdirs();
}

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("UTF-8");
List<?> items = upload.parseRequest(request);
Iterator<?> itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
String fileName = item.getName();
if (!item.isFormField()) {
// 检查文件大小
if (item.getSize() > IMAGE_MAX_SIZE) {
response.getWriter().write("上传文件大小超过限制。");
return null;
}
// 检查扩展名
String fileExt = fileName.substring(
fileName.lastIndexOf(".") + 1).toLowerCase();
if (!ext.contains(fileExt)) {
response.getWriter().write(
"上传文件扩展名是不允许的扩展名。\n只允许" + ext + "格式。");
return null;
}

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String tempName = df.format(new Date()) + "_"
+ new Random().nextInt(1000);
String newFileName = tempName+ "." + fileExt;

try {
File uploadedFile = new File(savePath, newFileName);
item.write(uploadedFile);
} catch (Exception e) {
e.printStackTrace();
response.getWriter().write("上传文件失败。");
return null;
}
String compressFileName = "comp_"+tempName+"."+ fileExt;
CompressPicDemo mypic = new CompressPicDemo();
mypic.compressPic(savePath, savePath, newFileName, compressFileName, Integer.parseInt(imageWidth), Integer.parseInt(imageHeight), false);
JSONObject obj = new JSONObject();
obj.put("error", 0);
obj.put("url", saveUrl + compressFileName);
response.getWriter().write(obj.toString());
return null;
}
}
return null;

}


java.lang.reflect.InvocationTargetException
        at sun.reflect.GeneratedMethodAccessor107.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at com.wm.web.util.ActionInfo.execute(ActionInfo.java:40)
        at com.wm.web.WebCtrol.dispatch(WebCtrol.java:105)
        at com.wm.web.WebCtrol.doPost(WebCtrol.java:52)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
        at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
        at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
        at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.wm.filter.EncodingFilter.doFilter(EncodingFilter.java:29)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
        at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2239)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
        at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. null
        at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:367)
        at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
        at com.wm.business.image.ctrol.ImageCtrol.uploadCompressImage(ImageCtrol.java:329)
        ... 31 more
Caused by: java.net.SocketTimeoutException
        at org.apache.coyote.http11.InternalAprInputBuffer.fill(InternalAprInputBuffer.java:801)
        at org.apache.coyote.http11.InternalAprInputBuffer$SocketInputBuffer.doRead(InternalAprInputBuffer.java:835)
        at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:116)
        at org.apache.coyote.http11.InternalAprInputBuffer.doRead(InternalAprInputBuffer.java:743)
        at org.apache.coyote.Request.doRead(Request.java:427)
        at org.apache.catalina.connector.InputBuffer.realReadBytes(InputBuffer.java:304)
        at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:419)
        at org.apache.catalina.connector.InputBuffer.read(InputBuffer.java:327)
        at org.apache.catalina.connector.CoyoteInputStream.read(CoyoteInputStream.java:193)
        at org.apache.commons.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:977)
        at org.apache.commons.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:887)
        at java.io.InputStream.read(InputStream.java:82)
        at org.apache.commons.fileupload.util.Streams.copy(Streams.java:94)
        at org.apache.commons.fileupload.util.Streams.copy(Streams.java:64)
        at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:362)
        ... 33 more



发表新帖 发表回复