将数据从Servlet发送到HTML

编程入门 行业动态 更新时间:2024-10-28 09:20:27
本文介绍了将数据从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

本文发布于:2023-10-28 18:53:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537481.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   数据   Servlet   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!