[英]what is JSON REST interface
Is there any tutorial on JSON RESTful interface (using JAVA servlet ) ? 是否有关于JSON RESTful接口的教程(使用JAVA servlet )? The purpose is to call to external REST interface for data, and handle the data by the client(javascript client).
目的是调用外部REST接口获取数据,并由客户端(javascript客户端)处理数据。
I am not sure what kind of thing is exactly JSON REST interface in JAVA... I need some tutorials to start to learn, so...I ask here. 我不确定JAVA中JSON REST界面究竟是什么类型的东西...我需要一些教程才能开始学习,所以...我在这里问。
JSON is a light-weight data serialization format based on a subset of JavaScript. JSON是一种基于JavaScript子集的轻量级数据序列化格式。
A RESTful interface is one that conforms to the constraints and characteristics of the REST architectural style . RESTful接口是符合REST架构风格的约束和特征的接口。
So, combining the two, a JSON RESTful interface is one that follows the REST architectural style and uses JSON as its data representation format (typically the content type application/json
). 因此,结合这两者,JSON RESTful接口是遵循REST架构风格并使用JSON作为其数据表示格式(通常是内容类型
application/json
)的接口。
To implement a service of this kind in Java there are frameworks that can help you, such as Jersey or RESTEasy . 要在Java中实现此类服务,可以使用可以帮助您的框架,例如Jersey或RESTEasy 。 Both offer additional components that support JSON (for both incoming and outgoing data).
两者都提供了支持JSON的附加组件(用于传入和传出数据)。
Both Jersey and RESTEasy implement the JAX-RS spec, so it's possible to use either as a 'pure' Java EE way of doing things. Jersey和RESTEasy都实现了JAX-RS规范,因此可以将它们用作“纯粹的”Java EE处理方式。 If you want to use only the Servlet part of Java EE to do this, it's possible but you'll have to do things like parsing path/template parameters from the URI yourself.
如果您只想使用Java EE的Servlet部分来执行此操作,则可能需要执行此操作,例如自己从URI解析路径/模板参数。
You may find it difficult to use servlet-mapping
elements to describe your resource URLs, and this might result in you implementing something that looks very much like JAX-RS (if you end up with one controller servlet that parses the URI and dispatches the request to another object). 您可能会发现很难使用
servlet-mapping
元素来描述资源URL,这可能会导致您实现与JAX-RS非常相似的内容(如果您最终得到一个解析URI并调度请求的控制器servlet)到另一个对象)。
I'd suggest reading a lot more on REST before you decide how to implement this. 在你决定如何实现之前,我建议你阅读更多有关REST的内容。 Here's some pointers:
这里有一些指示:
HttpSession
. HttpSession
。 Finally, if you go the 'pure Servlets' route, you may still find reading/creating JSON a lot easier using a parser library like Jackson . 最后,如果您使用'纯Servlets'路径,您仍然可以使用像Jackson这样的解析器库轻松读取/创建JSON。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.