From 2bbf010912bafed31733f760ace2866d0b435e86 Mon Sep 17 00:00:00 2001 From: mhqpx Date: Sun, 31 Dec 2017 12:09:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=87=E4=BB=B6=E9=A2=84=E8=A7=88:=E7=A7=BB?= =?UTF-8?q?=E9=99=A4needE=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yudianbank/utils/DownloadUtils.java | 12 ++++++++---- .../main/java/com/yudianbank/utils/SimTextUtil.java | 4 ++-- .../web/controller/OnlinePreviewController.java | 8 ++++---- jodconverter-web/src/main/resources/web/compress.ftl | 3 +-- jodconverter-web/src/main/resources/web/index.ftl | 2 +- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/jodconverter-web/src/main/java/com/yudianbank/utils/DownloadUtils.java b/jodconverter-web/src/main/java/com/yudianbank/utils/DownloadUtils.java index a19b3ec7..67b5294b 100644 --- a/jodconverter-web/src/main/java/com/yudianbank/utils/DownloadUtils.java +++ b/jodconverter-web/src/main/java/com/yudianbank/utils/DownloadUtils.java @@ -27,10 +27,11 @@ public class DownloadUtils { * @param type * @return */ - public ReturnResponse downLoad(String urlAddress, String type, String fileName, String needEncode){ + public ReturnResponse downLoad(String urlAddress, String type, String fileName){ ReturnResponse response = new ReturnResponse<>(0, "下载成功!!!", ""); URL url = null; try { + urlAddress = replacePlusMark(urlAddress); urlAddress = encodeUrlParam(urlAddress); // 因为tomcat不能处理'+'号,所以讲'+'号替换成'%20%' urlAddress = urlAddress.replaceAll("\\+", "%20"); @@ -92,9 +93,12 @@ public class DownloadUtils { * @return */ private String replacePlusMark(String urlAddress) { - String nonParamStr = urlAddress.substring(0,urlAddress.indexOf("?") + 1); - String paramStr = urlAddress.substring(nonParamStr.length()); - return nonParamStr + paramStr.replace(" ", "+"); + if (urlAddress.contains("?")) { + String nonParamStr = urlAddress.substring(0,urlAddress.indexOf("?") + 1); + String paramStr = urlAddress.substring(nonParamStr.length()); + return nonParamStr + paramStr.replace(" ", "+"); + } + return urlAddress; } /** diff --git a/jodconverter-web/src/main/java/com/yudianbank/utils/SimTextUtil.java b/jodconverter-web/src/main/java/com/yudianbank/utils/SimTextUtil.java index 885be242..8b0b727e 100644 --- a/jodconverter-web/src/main/java/com/yudianbank/utils/SimTextUtil.java +++ b/jodconverter-web/src/main/java/com/yudianbank/utils/SimTextUtil.java @@ -17,8 +17,8 @@ public class SimTextUtil { @Autowired DownloadUtils downloadUtils; - public ReturnResponse readSimText(String url, String fileName, String needEncode){ - ReturnResponse response = downloadUtils.downLoad(url, "txt", fileName, needEncode); + public ReturnResponse readSimText(String url, String fileName){ + ReturnResponse response = downloadUtils.downLoad(url, "txt", fileName); return response; } } diff --git a/jodconverter-web/src/main/java/com/yudianbank/web/controller/OnlinePreviewController.java b/jodconverter-web/src/main/java/com/yudianbank/web/controller/OnlinePreviewController.java index 4b357bb8..8f16fc79 100644 --- a/jodconverter-web/src/main/java/com/yudianbank/web/controller/OnlinePreviewController.java +++ b/jodconverter-web/src/main/java/com/yudianbank/web/controller/OnlinePreviewController.java @@ -50,7 +50,7 @@ public class OnlinePreviewController { * @return */ @RequestMapping(value = "onlinePreview",method = RequestMethod.GET) - public String onlinePreview(String url, String needEncode, Model model, HttpServletRequest req) throws UnsupportedEncodingException { + public String onlinePreview(String url, Model model, HttpServletRequest req) throws UnsupportedEncodingException { // 路径转码 String decodedUrl = URLDecoder.decode(url, "utf-8"); String type = typeFromUrl(url); @@ -62,7 +62,7 @@ public class OnlinePreviewController { model.addAttribute("imgurl", url); return "picture"; } else if (type.equalsIgnoreCase("simText")){ - ReturnResponse response = simTextUtil.readSimText(decodedUrl, fileName, needEncode); + ReturnResponse response = simTextUtil.readSimText(decodedUrl, fileName); if (0 != response.getCode()) { model.addAttribute("msg", response.getMsg()); return "fileNotSupported"; @@ -76,7 +76,7 @@ public class OnlinePreviewController { String fileTree = null; // 判断文件名是否存在(redis缓存读取) if (!StringUtils.hasText(fileUtils.getConvertedFile(fileName))) { - ReturnResponse response = downloadUtils.downLoad(decodedUrl, suffix, fileName, needEncode); + ReturnResponse response = downloadUtils.downLoad(decodedUrl, suffix, fileName); if (0 != response.getCode()) { model.addAttribute("msg", response.getMsg()); return "fileNotSupported"; @@ -109,7 +109,7 @@ public class OnlinePreviewController { if (!fileUtils.listConvertedFiles().containsKey(pdfName)) { String filePath = fileDir + fileName; if (!new File(filePath).exists()) { - ReturnResponse response = downloadUtils.downLoad(decodedUrl, suffix, null, needEncode); + ReturnResponse response = downloadUtils.downLoad(decodedUrl, suffix, null); if (0 != response.getCode()) { model.addAttribute("msg", response.getMsg()); return "fileNotSupported"; diff --git a/jodconverter-web/src/main/resources/web/compress.ftl b/jodconverter-web/src/main/resources/web/compress.ftl index a904bc14..1a2e4bf2 100644 --- a/jodconverter-web/src/main/resources/web/compress.ftl +++ b/jodconverter-web/src/main/resources/web/compress.ftl @@ -69,8 +69,7 @@ fulls += ",resizable"; // 对于不支持screen属性的浏览器,可以手工进行最大化。 manually } window.open("onlinePreview?url=" - + encodeURIComponent("${baseUrl}" + treeNode.fileName) - + "&needEncode=1", "_blank",fulls); + + encodeURIComponent("${baseUrl}" + treeNode.fileName), "_blank",fulls); } } } diff --git a/jodconverter-web/src/main/resources/web/index.ftl b/jodconverter-web/src/main/resources/web/index.ftl index 8ef5fa8c..243bb3ac 100644 --- a/jodconverter-web/src/main/resources/web/index.ftl +++ b/jodconverter-web/src/main/resources/web/index.ftl @@ -125,7 +125,7 @@ // 每个data添加一列用来操作 $(data).each(function (index, item) { item.action = "预览" + + + encodeURIComponent('${baseUrl}' + item.fileName ) +"'>预览" + "删除"; }); return data;