将 URL 从 AppEngine 发送到 Java 应用程序
我正在使用带有 Google AppEngine 的 Java 应用程序。我向 servlet 发送 post 请求,它需要使用一些未知数量的 URL 进行响应。
我想知道实现这一点的最佳方法是什么。在应用程序中创建 URL 对象并将其作为 JSON 发送,或者然后在 Java 应用程序中重新转换它,或者只是将 URL 作为带有某些分隔符的字符串发送?
有没有办法像我们处理请求对象一样在响应对象中发送参数,或者设置 MIME 类型,以便我们可以在 Java 应用程序中轻松获取 URL?
I'm using a Java application with Google AppEngine. I send post requests to the servlet and it needs to response with some unknown number of URL's.
I was wondering what would be the best way to implement this. Making URL object in the app and sending it as JSON or then reconverting it in the Java application or just sending the URLs as String with some delimiter ?
Is there a way to send parameters in response objects like we do with request objects or maybe set the MIME type so we can get the URLs easily in the Java application ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议只返回一个 JSON 数组; Java 中有一些很好的库(请参阅 Jackson Vs. Gson)来从 Java 对象创建 JSON 并解析 JSON在 javascript 中显然是一个已解决的问题。依靠众所周知的代码来完成所有编码/解码是一个巨大的帮助。
I'd recommend just returning a JSON array; there are good libraries in Java (see Jackson Vs. Gson) to create JSON from Java objects and parsing JSON in javascript is obviously a solved problem. Relying on well-known code to do all the encoding/decoding is a huge help.