我这个upload哪里错了?

holy_pkzzl holy_pkzzl 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
怎摸我的/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() {
}
}
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
holy_pkzzl
Java SE 62,621 成员 307,251 内容