问题描述
- jspsmartupload上传出错
-
代码如下<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ page import="com.jspsmart.upload.*,java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">Insert title here
产品图片
<% request.setCharacterEncoding("utf-8");
SmartUpload mySmartUpload=new SmartUpload();
mySmartUpload.initialize(pageContext);
long max=2*1024*1024;
String uri="D:/workspace/MyFirstWeb/WebContent/image/";
try { mySmartUpload.setAllowedFilesList("jpg,png");
mySmartUpload.upload();
} catch (Exception e) {
%>
<br><br>
alert("只允许上传.jpg和.png类型图片文件");<br>
<%
}
try{
com.jspsmart.upload.File myFile=mySmartUpload.getFiles().getFile(0);
String myFileName=myFile.getFileName();
String ext=myFile.getFileExt();
int file_size=myFile.getSize();
String saveurl="";
if (file_size>max){ %>
alert("图片大小上限为2m");<br>
//location.href="addproduct2.jsp";<br><%}
else{Calendar calendar=Calendar.getInstance();
String filename=String.valueOf(calendar.getTimeInMillis());
saveurl=uri;
saveurl=saveurl+filename+"."+ext; session.setAttribute("save",saveurl);
myFile.saveAs(saveurl,File.SAVEAS_PHYSICAL); }
out.print(saveurl);
}
catch(Exception e){e.printStackTrace();}
%>报错如下java.lang.IllegalArgumentException: Files' name is invalid or does not exist (1205).
at com.jspsmart.upload.Files.getFile(Files.java:73)
at org.apache.jsp.zzzzzzzz_jsp._jspService(zzzzzzzz_jsp.java from :73)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:486)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:47)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
at org.eclipse.jetty.server.Server.handle(Server.java:350)
at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454)
at org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:900)
at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:954)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:851)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:606)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538)
at java.lang.Thread.run(Thread.java:662)
昨天还能用的 为啥今天就不行了呢
解决方案
报那么明显的错,文件名无效或者不存在,73行getFile()的文件名那错了