简体   繁体   English

如何将数据从服务器(REST api 响应)推送/发送到 jsp/html 表单

[英]How to push/send data from server (REST api response) to a jsp/html form

My requirement is as below我的要求如下

A user before scanning a label will open the web application(spring-boot) and click on a link which shows an empty html form.用户在扫描标签之前将打开 Web 应用程序(spring-boot)并单击显示空 html 表单的链接。 Now when he scans the label, the details of that scan should auto populate in the form that he had opened.现在,当他扫描标签时,扫描的详细信息应该会自动填充到他打开的表单中。 Behind the scenes, the same application will also expose a REST api which receives the the details of the scan in JSON format.在幕后,同一个应用程序还将公开一个 REST api,它以 JSON 格式接收扫描的详细信息。 This json values should be pushed automatically to the form that is already open.此 json 值应自动推送到已打开的表单。

Are websockets a way to fulfill the above requirement? websockets 是满足上述要求的一种方式吗? Or is there a better/easier way to do this?或者有没有更好/更简单的方法来做到这一点?

Thanks.谢谢。

Web sockets is definitely a viable option. Web 套接字绝对是一个可行的选择。

A pure HTTP based solution would be polling:一个纯粹的基于 HTTP 的解决方案是轮询:

You can use short polling : The client asks for new data every few seconds.您可以使用短轮询:客户端每隔几秒钟就会请求新数据。

Or long polling : The server holds the http request until new data is ready for the client and responds with the data.长轮询:服务器保持 http 请求,直到为客户端准备好新数据并用数据响应。 Then the client immediately sends a new request and the server holds request again ...然后客户端立即发送一个新请求,服务器再次持有请求......

Here is a nice explanation about polling and how to implement long polling in Spring这是关于轮询以及如何在 Spring 中实现长轮询的一个很好的解释

https://spring.io/blog/2012/05/14/spring-mvc-3-2-preview-adding-long-polling-to-an-existing-web-application https://spring.io/blog/2012/05/14/spring-mvc-3-2-preview-adding-long-polling-to-an-existing-web-application

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM