uAvater.jsp
<form action="/SongTaste/member.do?method=editpic" method="post" encType=multipart/form-data>
<table align="center" width=700>
<tr>
<td>头像:</td>
<td><input type="file" name="picture" size=30></td>
<td><input type="submit" value="上传图片"></td>
</tr> </table>
</form>
MemberAction.java
public class MemberAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String method = request.getParameter("method");
if("editpic".equals(method)){ // 修改会员头像
try {
return editpic(mapping,form,request,response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
/*
* 修改会员图片
*/
public ActionForward editpic(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws ServletException, SmartUploadException{
String ext=null;
String filename=null;
SmartUpload smartupload=new SmartUpload();
smartupload.initialize(getServlet(), request, response);
smartupload.setAllowedFilesList("jpg,gif,png,JPG,GIF,PNG"); //只允许上传此类文件
try {
System.out.println("This is the 1 Test");
smartupload.upload();
com.jspsmart.upload.File smartFile=smartupload.getFiles().getFile(0);
ext=smartFile.getFieldName(); //获取上传文件的后缀名
Calendar calendar = Calendar.getInstance();
filename=String.valueOf(calendar.getTimeInMillis()); //更改文件名,取得当前上传时间的毫秒数值
smartFile.saveAs("/4/"+filename+"."+ext,smartFile.SAVEAS_VIRTUAL);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("modefyPIC");
}
15 个解决方案
#1
是不是文件太大?
#2
没有,就只有36.0K呢,好小的图片文件
#3
你走个断点看看卡在哪一步了?还有我记得上传文件好像要设置ContentType的内容,
request.setContentType("xx"),你到网上查查哈,好久都没写了,几步清楚了。
request.setContentType("xx"),你到网上查查哈,好久都没写了,几步清楚了。
#4
断点就是在 smartupload.upload();我这边的编译器也是一点错误都没报,根本不知道出了什么错,就是卡在那儿不动了,至于ContentType虽然没用过,但在html中确实可以不需要的。
#5
等足夠長的時間可能會出來異常
或者看看有沒有設置超時之類的
#6
刚才等有挺久的,终于出来了这个错误,请高手分析下,看不懂呀。
2012-4-19 9:54:18 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class java.lang.IllegalArgumentException
2012-4-19 9:54:18 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.IllegalArgumentException: Files' name is invalid or does not exist (1205).
at com.jspsmart.upload.Files.getFile(Files.java:73)
at com.action.MemberAction.editpic(MemberAction.java:195)
at com.action.MemberAction.execute(MemberAction.java:50)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:619)
2012-4-19 9:54:18 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class java.lang.IllegalArgumentException
2012-4-19 9:54:18 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.IllegalArgumentException: Files' name is invalid or does not exist (1205).
at com.jspsmart.upload.Files.getFile(Files.java:73)
at com.action.MemberAction.editpic(MemberAction.java:195)
at com.action.MemberAction.execute(MemberAction.java:50)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:619)
#7
我刚才想了下,还是原来那句smartupload.upload();错误,导致后面的SmartFile得不到上传过来的文件,但又回到那个问题,smartupload.upload();这句到底是错在哪儿呢?
#8
ext=smartFile.getFieldName(); //获取上传文件的后缀名
获取后缀名用getFileExt()方法。。
获取后缀名用getFileExt()方法。。
#9
這個是服務端報的錯,找不到文件,我看了下,上傳之前(upload)要先將文件準備好吧?你這邊是之後才get的
或者直接去找下標準的smartupload使用程序好了
或者直接去找下標準的smartupload使用程序好了
#10
大哥,在标准的smartupload里面,就是先初始化后直接使用upload()这个方法的.........
#11
看來你瞭解標準程序,那这个程序和你所瞭解的標準程序差別在哪呢
#12
不管其他,單看異常的話,它所揭示的就是upload之前文件名(文件)沒準備好,這又怎麼解釋,upload後面幾句沒執行到吧
#13
遇到一样的问题,纠结中···
#14
我也遇到这个问题了,抓狂中。。。。。。。。。。。
#15
问题依然在啊,有没有解决方法,单写的例子上传的好好地一放到项目里面就在uoload停住了。跪求大神。
#1
是不是文件太大?
#2
没有,就只有36.0K呢,好小的图片文件
#3
你走个断点看看卡在哪一步了?还有我记得上传文件好像要设置ContentType的内容,
request.setContentType("xx"),你到网上查查哈,好久都没写了,几步清楚了。
request.setContentType("xx"),你到网上查查哈,好久都没写了,几步清楚了。
#4
断点就是在 smartupload.upload();我这边的编译器也是一点错误都没报,根本不知道出了什么错,就是卡在那儿不动了,至于ContentType虽然没用过,但在html中确实可以不需要的。
#5
等足夠長的時間可能會出來異常
或者看看有沒有設置超時之類的
#6
刚才等有挺久的,终于出来了这个错误,请高手分析下,看不懂呀。
2012-4-19 9:54:18 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class java.lang.IllegalArgumentException
2012-4-19 9:54:18 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.IllegalArgumentException: Files' name is invalid or does not exist (1205).
at com.jspsmart.upload.Files.getFile(Files.java:73)
at com.action.MemberAction.editpic(MemberAction.java:195)
at com.action.MemberAction.execute(MemberAction.java:50)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:619)
2012-4-19 9:54:18 org.apache.struts.action.RequestProcessor processException
警告: Unhandled Exception thrown: class java.lang.IllegalArgumentException
2012-4-19 9:54:18 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet action threw exception
java.lang.IllegalArgumentException: Files' name is invalid or does not exist (1205).
at com.jspsmart.upload.Files.getFile(Files.java:73)
at com.action.MemberAction.editpic(MemberAction.java:195)
at com.action.MemberAction.execute(MemberAction.java:50)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:228)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:216)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:634)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:445)
at java.lang.Thread.run(Thread.java:619)
#7
我刚才想了下,还是原来那句smartupload.upload();错误,导致后面的SmartFile得不到上传过来的文件,但又回到那个问题,smartupload.upload();这句到底是错在哪儿呢?
#8
ext=smartFile.getFieldName(); //获取上传文件的后缀名
获取后缀名用getFileExt()方法。。
获取后缀名用getFileExt()方法。。
#9
這個是服務端報的錯,找不到文件,我看了下,上傳之前(upload)要先將文件準備好吧?你這邊是之後才get的
或者直接去找下標準的smartupload使用程序好了
或者直接去找下標準的smartupload使用程序好了
#10
大哥,在标准的smartupload里面,就是先初始化后直接使用upload()这个方法的.........
#11
看來你瞭解標準程序,那这个程序和你所瞭解的標準程序差別在哪呢
#12
不管其他,單看異常的話,它所揭示的就是upload之前文件名(文件)沒準備好,這又怎麼解釋,upload後面幾句沒執行到吧
#13
遇到一样的问题,纠结中···
#14
我也遇到这个问题了,抓狂中。。。。。。。。。。。
#15
问题依然在啊,有没有解决方法,单写的例子上传的好好地一放到项目里面就在uoload停住了。跪求大神。