• 大小: 4.1MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-17
  • 语言: 其他
  • 标签: bootstrap  前端框架  

资源简介

bootstrap 文件上传,可以进行文件上传,利用bootstrap插件进行文件上传,代码前后端

资源截图

代码片段和文件信息

package org.a;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

public class FileUpload extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public FileUpload() {
super();
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request HttpServletResponse
 *      response)
 */
protected void doGet(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {
response.setCharacterEncoding(“UTF-8“);
response.setContentType(“application/json; charset=utf-8“);
PrintWriter out = null;
try {
out = response.getWriter();
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
// 存放的路徑 tomcat在那个磁盘 /就表示哪个盘
String targetFoder = “/myfile/“;
File t = new File(targetFoder);
if (!t.exists() && !t.isDirectory()) {
t.mkdirs();
}
File file1 = null;
List list = upload.parseRequest(request); // 解析request请求
for (FileItem fileItem : list) {
if(fileItem.getName()!=null){
file1 = new File(targetFoder + fileItem.getName());
file1.createNewFile();
InputStream ins = fileItem.getInputStream();
OutputStream ous = new FileOutputStream(file1);
try {
byte[] buffer = new byte[1024];
int len = 0;
while ((len = ins.read(buffer)) > -1)
ous.write(buffer 0 len);
} finally {
ous.close();
ins.close();
}
}
}
String jsonStr = “{\“result\“:\“success\“}“;
out.write(jsonStr);
} catch (Exception e) {
out.write(“{\“result\“:\“error\“}“);
} finally {
if (out != null) {
out.close();
}
}
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request HttpServletResponse
 *      response)
 */
protected void doPost(HttpServletRequest request HttpServletResponse response)
throws ServletException IOException {

doGet(request response);
}

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-02-23 09:57  demo\
     文件         842  2017-02-23 09:57  demo\.classpath
     文件        1037  2017-02-23 09:57  demo\.project
     目录           0  2017-02-23 10:25  demo\.settings\
     文件         567  2017-02-23 09:57  demo\.settings\.jsdtscope
     文件         364  2017-02-23 09:57  demo\.settings\org.eclipse.jdt.core.prefs
     文件         106  2017-02-23 10:25  demo\.settings\org.eclipse.ltk.core.refactoring.prefs
     文件         464  2017-02-23 09:57  demo\.settings\org.eclipse.wst.common.component
     文件         345  2017-02-23 10:25  demo\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2017-02-23 09:57  demo\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2017-02-23 09:57  demo\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2017-02-23 10:22  demo\WebContent\
     目录           0  2017-02-23 09:57  demo\WebContent\meta-INF\
     文件          39  2017-02-23 09:57  demo\WebContent\meta-INF\MANIFEST.MF
     目录           0  2017-02-23 09:57  demo\WebContent\WEB-INF\
     目录           0  2017-11-29 20:44  demo\WebContent\WEB-INF\lib\
     文件       43578  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\asm-3.3.jar
     文件       38275  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\asm-commons-3.3.jar
     文件       21503  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\asm-tree-3.3.jar
     文件       70282  2017-02-23 10:55  demo\WebContent\WEB-INF\lib\commons-fileupload-1.3.2.jar
     文件      208700  2017-02-23 10:55  demo\WebContent\WEB-INF\lib\commons-io-2.5.jar
     文件      315805  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\commons-lang3-3.1.jar
     文件       62050  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\commons-logging-1.1.3.jar
     文件      931168  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\freemarker-2.3.19.jar
     文件      614203  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\javassist-3.11.0.GA.jar
     文件      489884  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\log4j-1.2.17.jar
     文件      227997  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\ognl-3.0.6.jar
     文件      802737  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\struts2-core-2.3.15.3.jar
     文件      640652  2017-02-23 12:04  demo\WebContent\WEB-INF\lib\xwork-core-2.3.15.3.jar
     文件         649  2017-02-23 12:22  demo\WebContent\WEB-INF\web.xml
     目录           0  2017-02-23 10:49  demo\WebContent\fileinput\
............此处省略35个文件信息

评论

共有 条评论