如何显示包含来自jsp的javascript的外部网站?

如何显示包含来自jsp的javascript的外部网站?,java,html,jsp,servlets,Java,Html,Jsp,Servlets,我必须在jsp中嵌入一个HTML文件。此HTML文件是动态的,必须根据用户请求下载。我尝试的是将html下载到一个目录中,然后从jsp中显示它 因为我尝试的方法之一是这样的: public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentTy

我必须在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();
    }        
}
<%@ include file="/web/external.html" %>
我试图直接从网页上阅读。但同样的问题是,Java脚本不工作,页面内容也没有加载

但当我点击下载的html时,一切都正常工作,但当我在jsp中导入它时,一切都不起作用。我怎样才能解决这个问题

尝试将其包含在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();
    }        
}
<%@ include file="/web/external.html" %>


还是不走运。不使用iframe的最佳方法是什么?(我计划呈现的网站不支持iframe)

上述问题的解决方案是在jsp中添加以下内容:

<%@ taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>

<html>
   <head>
      <title> Tag Example</title>
   </head>

   <body>
      <c:import var = "data" url = "${page}"/>
      <c:out value = "${data}" escapeXml="false"/>
   </body>
</html>

使用了
c标记库
,并且必须使用
escapeXml=“false”
来实现此功能

你试过使用
块吗?@killjoy什么是
块?@killjoy这有什么帮助?这就是js。我需要在jsp中呈现整个网站。不仅是脚本。这个网站是动态的,可以是任何网站。哦,我以为你说的是JS,不是JSP。我的错。