weixin_33690963 2013-04-19 05:25 采纳率: 0%
浏览 745

HTML页面调用JSP文件

I have a HTML page on my computer and a JSP file on a distant server.

Now how do I,

Display content from the JSP file into the HTML page.

The HTML page must be strictly HTML (no server-side language), but can use AJAX/JavaScript.

Is it even possible to get the information from the server through the JSP page without turning the HTML page into a JSP file itself? How would I implement it?

  • 写回答

2条回答 默认 最新

  • weixin_33743703 2013-04-19 05:42
    关注
    <script type="text/javascript" src="js/jquery.min.js"></script> 
    // I have jquery.js under js directory in my webapp
    <script type="text/javascript">
      var url = "my.jsp";
      $(function(){
            $.ajax({
                url : url, // Pass you Servlet/ JSP Url
                dataType : 'html',
                success : function(response) {
                    alert('Success');
                    $('#output').html(response);
                },
                error : function(request, textStatus, errorThrown) {
                    alert(request.status + ', Error: ' + request.statusText);
                               // perform tasks for error 
                }
            });
    });
    </script>
    

    JSP

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <%
    
    out.println("<h1>Hello World</h1>"); // Write html values here
    %>
    

    Your HTML

    .... <div id="output"></div>

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料