如何将数据从常规无状态servlet传递到后端实例? [英] How to pass data from regular stateless servlet to backend instance?

查看:174
本文介绍了如何将数据从常规无状态servlet传递到后端实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有使用过Google App Engine的后端系统,并且由于缺乏样本和详细的文档,我感到非常困惑。

假设我有一个投票应用程序。我想收集常规无状态GAE servlet中的投票,然后将数据传递给驻留的后端实例,并处理我的数据。如何将数据从常规servlet传递到后端servlet?我如何分配哪些servlet类是普通的servlet,哪些servlet只能在后端实例中处理?如果我有两个后端--B1类和B2类,我不知道该如何将servlet分配到后端的config.xml中。



我如何在无状态servlet代码中选择后端现在处于活动状态?我听说我应该使用网址提取与后台对话,但是如何?我没有发现如何通过后端实例进行迭代。



请指教:) 解决方案

您应该首先阅读后端文档


如何将数据从常规servlet传递到后端servlet?

您有几个选项 - 通过将数据粘贴到内存缓存或数据存储区间接传递它。或者直接使用URLFetch向后端发送请求(请参阅下面的寻址信息)


如何分配哪些servlet类是正常的


文档位于后端配置解释说你不能这样做(但),尽管你可以将它们标记为admin,所以它们是不适用于公众:


后端共享web.xml中定义的servlet与主应用程序版本的集合。目前不可能为每个后端配置一组单独的servlet。


寻址后端部分包含如何连接到特定的后端:


后端实例可以通过http请求http:// [instance]。[backend ]。[app] .appspot.com,或者在您的应用程序的自定义域中。如果您的目标是未使用http:// [backend]。[app] .appspot.com定位实例,则App Engine将选择第一个可用的后端实例。


当您配置您的后端时,您会为它们指定名称,这些名称将进入上述url方案中的[backend]插槽。如果你想发送一个http请求到第一个可用的B1实例,你可以使用类似于http://B1.ruslansapp.appspot.com/dosomething/

I've never used Google App Engine backends and I'm very confused by lack of samples and detailed documentation.

Let's say I have a voting app. I want to collect votes in regular stateless GAE servlet and then pass the data to backend instance that is resident and it processes my data. How can I pass data from regular servlet to backend servlet ? How do I assign what servlet class is normal servlet and what servlet should be handled only in backend instance? I don't see how I can assign servlet to backend in config xml.

Or what if I have two backends - class B1 and class B2. How can I choose in code of stateless servlet what backends are active right now? I heard that I should use URL Fetch to talk to backends but how ? I didn't find how I can iterate through backend instances.

Please advise :)

解决方案

You should start by reading the documentation on backends

How can I pass data from regular servlet to backend servlet ?

You have a few options - pass it indirectly by sticking data in memcache or the datastore. Or pass it directly by using URLFetch to make requests to your backends (see addressing info below)

How do I assign what servlet class is normal servlet and what servlet should be handled only in backend instance?

The doc on Backend Configuration explains that you can't do that (yet), though you can mark them as admin only so they are not available to the public:

Backends share the set of servlets defined in web.xml with your main application version. It is not possible at the moment to configure a separate set of servlets for each backend.

The "Addressing Backends" section includes info on how to connect to a specific backend:

A backend instance can be targeted with HTTP requests to http://[instance].[backend].[app].appspot.com, or at your application's custom domain. If you target a backend without targeting an instance using http://[backend].[app].appspot.com, App Engine selects the first available instance of the backend.

When you configure your backends , you give them names, which go into the [backend] slot in the url scheme described above. If you wanted to send a http request to the first available B1 instance, you would use something like http://B1.ruslansapp.appspot.com/dosomething/

这篇关于如何将数据从常规无状态servlet传递到后端实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆