天天看点

ssm ajax实现上传功能,SSM框架下,使用ajax请求上传文件(docdocxexcel图片等)(示例代码)...

1 packagecom.linrain.jcs.tool.downPOI.baseDown;2

3

6

7 importcom.linrain.jcs.tool.ConfigUtil;8 importorg.apache.poi.hwpf.HWPFDocument;9 importorg.apache.poi.hwpf.converter.PicturesManager;10 importorg.apache.poi.hwpf.converter.WordToHtmlConverter;11 importorg.apache.poi.hwpf.usermodel.PictureType;12 importorg.apache.poi.xwpf.converter.core.BasicURIResolver;13 importorg.apache.poi.xwpf.converter.core.FileImageExtractor;14 importorg.apache.poi.xwpf.converter.xhtml.XHTMLConverter;15 importorg.apache.poi.xwpf.converter.xhtml.XHTMLOptions;16 importorg.apache.poi.xwpf.usermodel.XWPFDocument;17 importorg.slf4j.Logger;18 importorg.slf4j.LoggerFactory;19 importorg.w3c.dom.Document;20

21 importjavax.xml.parsers.DocumentBuilderFactory;22 importjavax.xml.transform.OutputKeys;23 importjavax.xml.transform.Transformer;24 importjavax.xml.transform.TransformerFactory;25 importjavax.xml.transform.dom.DOMSource;26 importjavax.xml.transform.stream.StreamResult;27 import java.io.*;28 importjava.util.UUID;29

30

35 public classPoiUtil {36 private static final Logger log = LoggerFactory.getLogger(PoiUtil.class);37 //在html中图片保存的相对路径 static/images/upload38 //private static String imagePath = "\\\\static\\\\images\\\\upload\\\\";

39 private static String imagePath =ConfigUtil.getTempImagePath();40 private static String imagePathStr; //图片绝对地址

41 public static String rootPath;//项目跟路径

42 public static Long tempTime;//项目跟路径

43

44

47 static{48 RegexAnswerUtil regexAnswerUtil = newRegexAnswerUtil();49 rootPath =regexAnswerUtil.getRootPath();50 imagePathStr = rootPath +imagePath;51 log.info(" imagePathStr = " +imagePathStr);52 tempTime =ConfigUtil.getTempTime();53 }54

55

58 public static booleanhaveOvertime(String fileName) {59 boolean flag = false;60 if (fileName == null || fileName.length() < 14) {61 returnflag;62 }63 try{64 String substring = fileName.substring(0, 13);65 Long fileTime =Long.valueOf(substring);66 Long nowTime =System.currentTimeMillis();67 long l = nowTime -fileTime;68 //long time = 2 * 60 * 60 * 1000;//2个小时69 //long time = 2 * 60 * 1000;//2 分钟

70 if (l >tempTime) {71 flag = true;72