-
大小: 13KB文件类型: .java金币: 1下载: 0 次发布日期: 2021-05-14
- 语言: Java
- 标签: Upload KindEditor
资源简介
Spring Boot (程序篇):集成富文本编辑器KindEditor自动生成HTML静态页面并保存,上传 UploadController
代码片段和文件信息
package com.imenger.richlink.controller;
import com.fasterxml.jackson.databind.objectMapper;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author lvyimeng
* @version V1.0
* @title: richlink
* @Description: 上传
* @date: 2018/10/9 18:38
*/
@Controller
public class UploadController {
private static final objectMapper objectMapper = new objectMapper();
private PrintWriter writer = null;
@RequestMapping(value = “fileUpload“ method = RequestMethod.POST)
public void fileUpload(MultipartHttpServletRequest request
HttpServletResponse response) throws ServletException IOException
FileUploadException {
ServletContext application = request.getSession().getServletContext();
String savePath = application.getRealPath(“/“) + “attached/“;
// 文件保存目录URL
String saveUrl = request.getContextPath() + “/attached/“;
// 定义允许上传的文件扩展名
HashMap extMap = new HashMap();
extMap.put(“image“ “gifjpgjpegpngbmp“);
extMap.put(“flash“ “swfflv“);
extMap.put(“media“ “swfflvmp3wavwmawmvmidavimpgasfrmrmvb“);
extMap.put(“file“ “docdocxxlsxlsxppthtmhtmltxtziprargzbz2“);
// 最大文件大小
long maxSize = 1000000;
response.reset();
response.setCharacterEncoding(“UTF-8“);
response.setContentType(“text/html“);
writer = response.getWriter();
// writer.println(json); //想办法把map转成json
if (!ServletFileUpload.isMultipartContent(request)) {
writer.println(objectMapper.writeValueAsString(getError(“请选择文件。“)));
return;
}
// 检查目录
File uploadDir = new File(savePath);
if (!uploadDir.isDirectory()) {
writer.println(objectMapper.writeValueAsString(getError(“上传目录不存在。“)));
return;
}
// 检查目录写权限
if (!uploadDir.canWrite()) {
writer.println(objectMapper.writeValueAsString(getError(“上传目录没有写权限。“)));
return;
}
String dirName = request.getParameter(“dir“);
if (dirName == null) {
dirName = “image“;
相关资源
- commons-fileupload-1.2.2.jar和commons-io-2.4.
- webupload Java版轻松上传4个G文件
- jspsmartuploadUTF-8.jar
- Uploadify HTML5 收费版本($5) UploadFiv
- commons-fileupload.jar和commons-io.jar
- java文件上传案例
- commons-fileupload-1.2.2.jar和commons-io.jar
- 基于java的uploadify上传demo
- JSP使用C标签时必须引入的jar包,jst
- DiskFileItemFactory需要的jar包commons-file
- commons-fileupload-1.3.3.jar commons-io-2.5.ja
- commons-fileupload-1.2.1.jar和commons-io-1.3.
- 仿163网盘无刷新文件上传 for Jsp_file
- jsp 多文件上传(zyupload)
- SWFUpload实现多上传及上传进度显示
- 文件socket上传okhttpUpLoader
- java/jsp 上传+图片预览
- uploadify html5版本插件
- Uploadify和java后台实现多图上传
- 最全的common-FileUpload.jar包
- jspsmartupload组件
- java 批量上传文件带进度条,支持fl
- jsp 上传文件
评论
共有 条评论