java 上传文件 内存溢出_java - 服务器遇到内部错误(),导致服务器无法满足多文件上传请求 - 堆栈内存溢出...

任何人都可以帮助解决错误吗? 尝试在服务器文件夹中上传多个文件,文件名在数据库中,但是服务器抛出以下错误-

HTTP状态500

类型例外报告

信息

描述服务器遇到内部错误(),导致服务器无法满足此请求。

例外

java.io.IOException:java.io.FileNotFoundException:F:\\ eworkspace.metadata.plugins \\ org.eclipse.wst.server.core \\ tmp0 \\ wtpwebapps \\ UploadServlet30 \\ uploadFiles(拒绝访问)net.codejava.servlet.UploadServlet .doPost(UploadServlet.java:53)javax.servlet.http.HttpServlet.service(HttpServlet.java:641)javax.servlet.http.HttpServlet.service(HttpServlet.java:722)根本原因

java.io.FileNotFoundException:F:\\ eworkspace.metadata.plugins \\ org.eclipse.wst.server.core \\ tmp0 \\ wtpwebapps \\ UploadServlet30 \\ uploadFiles(拒绝访问)java.io.FileOutputStream.open(本机方法)java。 io.FileOutputStream。(未知源)java.io.FileOutputStream。(未知源)org.apache.tomcat.util.http.fileupload.disk.DiskFileItem.write(DiskFileItem.java:425)net.codejava.servlet.UploadServlet。 doPost(UploadServlet.java:53)javax.servlet.http.HttpServlet.service(HttpServlet.java:641)javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

控制器类

protected void doPost(HttpServletRequest request,

HttpServletResponse response) throws ServletException, IOException {

News news = new News();

// gets absolute path of the web application

String appPath = request.getServletContext().getRealPath("");

// constructs path of the directory to save uploaded file

String savePath = appPath + File.separator + UPLOAD_DIR;

// creates the save directory if it does not exists

File fileSaveDir = new File(savePath);

if (!fileSaveDir.exists()) {

fileSaveDir.mkdir();

}

for (Part part : request.getParts()) {

System.out.println("partttttttttt"+part.getName());

String fileName = extractFileName(part);

System.out.println("fle Name-----"+fileName);

// refines the fileName in case it is an absolute path

fileName = new File(fileName).getName();

System.out.println("fle Name-----"+fileName);

part.write(savePath + File.separator + fileName);

news.setFileName(fileName);

}

news.setNewsTitle(request.getParameter("newsTitle"));

news.setNewsDesc(request.getParameter("newsDesc"));

String newsId = request.getParameter("newsId");

if(newsId == null || newsId.isEmpty())

{

dao.addNews(news);

}

else

{

news.setNewsId(Integer.parseInt(newsId));

dao.updateNews(news);

}

RequestDispatcher view = request.getRequestDispatcher(LIST_NEWS);

request.setAttribute("newsList", dao.getAllNews());

view.forward(request, response);

}

/**

* Extracts file name from HTTP header content-disposition

*/

private String extractFileName(Part part) {

String contentDisp = part.getHeader("content-disposition");

String[] items = contentDisp.split(";");

for (String s : items) {

if (s.trim().startsWith("filename")) {

return s.substring(s.indexOf("=") + 2, s.length()-1);

}

}

return "";

}

和道

public void addNews(News news) {

String insertQuery = "INSERT INTO NEWSMASTER(NEWSID, NEWSTITLE, NEWSDESC,FILENAME) VALUES (?,?,?,?)";

try {

pStmt = dbConnection.prepareStatement(insertQuery);

pStmt.setInt(1, news.getNewsId());

pStmt.setString(2, news.getNewsTitle());

pStmt.setString(3, news.getNewsDesc());

pStmt.setString(4, news.getFileName());

pStmt.executeUpdate();

} catch (SQLException e) {

System.err.println(e.getMessage());

}

}

模型类

public String getFileName() {

return fileName;

}

public void setFileName(String fileName) {

this.fileName = fileName;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值