将数据从Servlet发送到HTML

问题描述:

我有一个生成json数据的servlet,我想将此json数据发送到html页面并在其中显示.

I have a servlet which generates json data and i want to send this json data to an html page and display it there.

现在,我不要要在url中附加json数据,然后在html中读取它,因为json数据可能很大且url有大小限制.

Now i dont want to append the json data in the url and then read it in the html, because the json data can be huge and url has a size limit.

我的需求需要html而不是jsp.

我无法在javascript中获得任何有效的解决方案.

I am not able to get any working solutions in javascript.

仍然在js,jquery或ajax中搜索相同的内容.

Still searching for the same in js,jquery or ajax.

请让我知道我可以尝试的替代方法,同样的示例值得赞赏

Please do let me know alternatives i can try out,examples of the same is appreciated

预先感谢

在您的html页面中编写此JQuery 包括jquery.js必要文件

In your html page write this JQuery Include jquery.js necessary files

<script>
$('a').click(function (event){ 
     event.preventDefault(); 
     $.post('../servlet_name',
            {
               param1:value1 //here incase you want to pass something to servlet
            },
            function(msg) {
                //msg is what u will get from the servlet
            });
});
</script>

在您的servlet中,使用

In your servlet pass the JSON using

PrintWriter out = response.getWriter();
out.print(jsondata);