Skip to content Skip to sidebar Skip to footer

Html Page Calls Jsp File

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 s

Solution 1:

<scripttype="text/javascript"src="js/jquery.min.js"></script> 
// I have jquery.js under js directory in my webapp
<scripttype="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>

Solution 2:

with using Ajax:

functionClickMe_Click()
{
    $.ajax({
        type:       "post",
        url:        "path/your.jsp",
        data:       {"param":"val"},
        success:    function(msg) {
                            alert(msg.data);//your info from jsp
            },
            error:function (xhr, ajaxOptions, thrownError){
                alert(thrownError);
            }  
    });

}

Post a Comment for "Html Page Calls Jsp File"