亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從jsp顯示包含javascript的外部網站?

如何從jsp顯示包含javascript的外部網站?

幕布斯6054654 2021-08-04 10:06:36
我必須在 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)
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號