Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
176 views
Welcome To Ask or Share your Answers For Others

1 Answer

<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>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...