From 70323b8ee332225647b0a0709f0434c115ec923f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E7=B2=BE=E5=8D=8E?= <842761733@qq.com> Date: Thu, 9 May 2019 15:02:02 +0800 Subject: [PATCH] =?UTF-8?q?pdf=E9=A2=84=E8=A7=88=E6=94=AF=E6=8C=81url?= =?UTF-8?q?=E4=B8=AD=E6=9C=89=E4=B8=AD=E6=96=87=E6=88=96=E7=89=B9=E6=AE=8A?= =?UTF-8?q?=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/OnlinePreviewController.java | 13 ++++--------- jodconverter-web/src/main/resources/web/pdf.ftl | 5 +++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/jodconverter-web/src/main/java/cn/keking/web/controller/OnlinePreviewController.java b/jodconverter-web/src/main/java/cn/keking/web/controller/OnlinePreviewController.java index d5376235..dc1ef23e 100644 --- a/jodconverter-web/src/main/java/cn/keking/web/controller/OnlinePreviewController.java +++ b/jodconverter-web/src/main/java/cn/keking/web/controller/OnlinePreviewController.java @@ -15,13 +15,8 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLDecoder; +import java.io.*; +import java.net.*; import java.util.Arrays; import java.util.List; @@ -98,7 +93,7 @@ public class OnlinePreviewController { InputStream inputStream = null; try { String strUrl = urlPath.trim(); - URL url = new URL(strUrl); + URL url = new URL(new URI(strUrl).toASCIIString()); //打开请求连接 URLConnection connection = url.openConnection(); HttpURLConnection httpURLConnection = (HttpURLConnection) connection; @@ -109,7 +104,7 @@ public class OnlinePreviewController { while (-1 != (len = inputStream.read(bs))) { resp.getOutputStream().write(bs, 0, len); } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { e.printStackTrace(); } finally { if (inputStream != null) { diff --git a/jodconverter-web/src/main/resources/web/pdf.ftl b/jodconverter-web/src/main/resources/web/pdf.ftl index 5b953512..0f621621 100644 --- a/jodconverter-web/src/main/resources/web/pdf.ftl +++ b/jodconverter-web/src/main/resources/web/pdf.ftl @@ -12,12 +12,12 @@
- <#if pdfUrl?contains("http://")> + <#if pdfUrl?contains("http://") || pdfUrl?contains("https://")> <#assign finalUrl="${pdfUrl}"> <#else> <#assign finalUrl="${baseUrl}${pdfUrl}"> #if> - + <#--