开发者

How to get the GWT base URL or Module Name from the GWT server scope?

I know you can get the GWT module name client side using GWT.getModuleName() or getHostPageBaseURL(), but is it possible to access it from the server?

What I'm after is the base URL of the deployed application. For example, if the GWT app is deployed as http://foo.com/deploy1/MyModule/ what I want to know is that the request came from the base URL of http://foo.com/deploy1/

Simply getting the URI from the HTTP request will give me开发者_JAVA百科 the full module path, when I really want the base (it will be deployed under different sub-paths at the same domain)


getContextPath() will give you the /deploy1 path.

If you need the full URL, you can easily reconstruct it from the other HttpServletRequest properties, or you can start with getRequestURL and tweak the result to replace the path part.


You need to understand the relationship between server and client in GWT.

So, you are looking at the usual Greetings GWT RPC stub and you see the client, server, shared folders (and you could add the public folder to place html, jsp or other files directly accessible thro the module's path).

What you probably do not realise is that the server-side responder to a client's RPC request need not be satisfied by a class within the module. Within the module you would have the RPC request definition interface where you define the server-side responder's path @RemoteServiceRelativePath("/hello").

To satisfy the RPC request thro the path "/hello", you do not need to code your servlet inside any module's "server" folder. You could even have

@RemoteServiceRelativePath("/hello.jsp")

or

@RemoteServiceRelativePath("/hello.php")

In fact, I have a login JSP which accepts RPC request from a few modules and it has to find out which module is emitting the request.

Or you could be using RequestBuilder or placing a JSON javascript-include request.

With that in mind, how would a RPC server-side responder be constrained to be defined by any module, regardless that it is placed inside the folder of a particular module? You simply have to have the client inform the server-side responder what module the client belongs to. Using a Map or HashMap as the datatype for RpC transmission would be very helpful. In case you are using REquestFactory, the identification of an entity would be able to tell your server what the module is through the entity object namespace.

http://h2g2java.blessedgeek.com/2009/08/gwt-rpc.html


You can inspect the Referer http header: http://en.wikipedia.org/wiki/HTTP_referrer


2 years late, but someone else may have the same question.

Anyway, you can get the that exact data you want by using GWT.getModuleBaseURL().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜