简体   繁体   English

服务器端javascript / java-javascript通信

[英]Server side javascript/java - javascript communication

A) Are there any resources of how to use server-side javascript without Node.js? A)是否有资源介绍如何在没有Node.js的情况下使用服务器端JavaScript?

B) Can a java-based server communicate with a javascript-based client? B)基于Java的服务器可以与基于JavaScript的客户端通信吗?

Both options are okay (I would be more happy with the B though). 两种选择都可以(尽管我会对B更满意)。

My goal is a simple client-server communication, and I think, that websocket still doesn't stand on two legs. 我的目标是进行简单的客户端-服务器通信,而且我认为websocket仍然没有两条腿。

I appreciate your answer. 感谢您的回答。

B is definitely possibly with Jersey JAX-RS and JSON encoded responses. B绝对可能与Jersey JAX-RS和JSON编码的响应一起使用。 It can automatically parse incoming JSON-formatted query (typically GET/PUT/DELETE) params or body (typically POST) parameters into POJOs and can transform returned POJOs into JSON for the response. 它可以自动将传入的JSON格式的查询(通常为GET / PUT / DELETE)参数或正文(通常为POST)参数解析为POJO,并将返回的POJO转换为JSON以进行响应。

More than possible we do it in production with a Marionette.js and Backbone.js based front-end. 我们在生产中使用基于Marionette.js和Backbone.js的前端做得更多。

WebSocket requires a bit of custom protocol work on your part and loses caching and other client optimizations. WebSocket需要您进行一些自定义协议的工作,并且会丢失缓存和其他客户端优化。 It is s best suited to realtime message-oriented or incremental binary upload/download workloads. 它最适合于面向实时消息或增量二进制上载/下载工作负载。

Probably the best part of the REST services that they are language-agnostic . REST服务最好的部分是不可知的 You can write serverside REST services in any language you want, then consume them from a completely different language. 您可以使用所需的任何语言编写服务器端REST服务,然后从完全不同的语言中使用它们。 The most basic example (what you mentioned in option B) is combining Java and JavaScript. 最基本的示例(您在选项B中提到的)是将Java和JavaScript结合在一起。 There are plenty of tutorials showing how to do that, maybe this one: 有很多教程展示了如何做到这一点,也许这是一个:

JAX-RS + JQuery JAX-RS + jQuery

is the best as a starter, because it highlights the important part. 首先是最好的,因为它突出了重要的部分。 Later on you may want to go for some more advanced JS library to produce production-ready code faster. 稍后,您可能希望使用一些更高级的JS库来更快地生产可用于生产的代码。

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

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