将数据从Servlet发送到HTML [英] Send data FROM Servlet to Html

查看:1198
本文介绍了将数据从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);

这篇关于将数据从Servlet发送到HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆