我必须在 jsp 中嵌入一个 HTML 文件。此 HTML 文件是动态的,必须根据用户请求进行下载。我尝试的是将html下载到一个目录中,然后从jsp中显示它。为此,我尝试过的其中一种方法是这样的:public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); PrintWriter out = response.getWriter(); String externalWeb = "external"; String externalWebValue = request.getParameter(externalWeb); _saveUrl(externalWebValue); StringBuilder contentBuilder = new StringBuilder(); try { BufferedReader in = new BufferedReader(new FileReader("/pathToExternal/external.html")); String str; while ((str = in.readLine()) != null) { contentBuilder.append(str); } in.close(); } catch (IOException e) { } String content = contentBuilder.toString(); String page = content; request.setAttribute("page", page); request.getRequestDispatcher("/web/external.jsp").forward(request, response); }private void _saveUrl(String externalWebValue) { try { PrintWriter outputFile = new PrintWriter("pathTo/external.html"); URL url = new URL(externalWebValue); URLConnection con = url.openConnection(); InputStream is =con.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); outputFile.println(line); } outputFile.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }我试图直接从网页上阅读。但同样的问题,javascripts 不起作用,页面内容没有加载。但是,当我单击下载的 html 时,一切正常,但是当我在 jsp 中导入它时,却没有任何效果。我怎样才能解决这个问题?试图像这样将它包含在jsp中:<%@ include file="/web/external.html" %>仍然没有运气。在不使用 iframe 的情况下执行此操作的最佳方法是什么?(我打算渲染的网站不支持 iframe)
添加回答
举报
0/150
提交
取消