我这个upload哪里错了?

holy_pkzzl 2007-03-16 07:31:08
怎摸我的/message(路径绝对正确)目录存在,但一运行就抛这个异常的?
Exception:

java.lang.ArrayIndexOutOfBoundsException: 0
newsf.UploadTest.doPost(UploadTest.java:31)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.27


我的upload的那个servlet是这样写的:

package newsf;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.upload.beans.Upload;

public class UploadTest
extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GB18030";
private Random rnd=new Random();

//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String path=getServletContext().getRealPath("message");
String name=null;

Upload up=new Upload();
up.init(request);
//up.setMaxFileSize(10 * 1024 * 1024);
up.setSaveDir(path);
up.setTagFileName(getRandName());

up.uploadFile();
name=up.getFileName()[0];
up.getParameter("title");
response.sendRedirect("message/"+name);
}

private String getRandName(){
return String.valueOf(rnd.nextLong());
}
//Clean up resources
public void destroy() {
}
}
...全文
165 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
holy_pkzzl 2007-03-16
  • 打赏
  • 举报
回复
common-io.jar?咋哪导入?能发个.jar给我吗?
holy_pkzzl 2007-03-16
  • 打赏
  • 举报
回复
catch了个ArrayIndexOutOfBoundsException是出异常啊~!?但怎摸改啊?
For_suzhen 2007-03-16
  • 打赏
  • 举报
回复

name=up.getFileName()[0];
catch 这一句试试,看看是不是着抛异常了
For_suzhen 2007-03-16
  • 打赏
  • 举报
回复
ArrayIndexOutOfBoundsException 明显的是数组越界了
wood_001 2007-03-16
  • 打赏
  • 举报
回复
name=up.getFileName()[0];
createthread 2007-03-16
  • 打赏
  • 举报
回复
common-io.jar导入了吗。。。。。。。。
holy_pkzzl 2007-03-16
  • 打赏
  • 举报
回复
upload.jar包绝对导入了。。。(补充)

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧