开发者

Pass login information from Apache/PHP to Tomcat/GWT

开发者 https://www.devze.com 2023-04-09 02:22 出处:网络
We are planning to deploy our GWT module as explained in http://code.google.com/webtoolkit/doc/1.6/DevGuideServerCommunication.html#DevGuideRPCDeployment

We are planning to deploy our GWT module as explained in http://code.google.com/webtoolkit/doc/1.6/DevGuideServerCommunication.html#DevGuideRPCDeployment under the section "Using Tomcat with Apache HTTPD and a proxy"

Basically, we configured Apache/PHP server to pass on the requests to a Tomcat/GWT server that match a part of the URL. That worked as expected. Now we would like to pass the information of the currently logged in user from Apache/PHP to the GWT module.

My initial idea was to load the GWT module from a PHP page (by including it's nocache.js) and include a login token with it which the GWT module can read. But I am not sure if it is safe to read a DOM value and consider that as a login token.

Any suggestions for what would be the best w开发者_Python百科ay to do it? Thank you.


IMHO it is definitifly the best idea to use a login-token, that is passed from apache/php to your gwt project. To pass this token, you have three possibilities:

First one: You can pass your token using a cookie. Write your token into a cookie and read it again in your GWT-context:

import com.google.gwt.user.client.Cookies;
Collection<String> cookies = Cookies.getCookieNames();

An example on dealing with cookies from GWT you can find in the GWT-Showcase.

Second one: Instead of writing your token to a cookie, you can pass it with a HTTP GET and read this again within your GWT-context:

// returns whole query string 
public static String getQueryString() {
    return Window.Location.getQueryString();
}

// returns specific parameter
public static String getQueryString(String name) {   
    return Window.Location.getParameter(name);
}

This method is -IMHO- that one you should never ever choose!

Third one: Instead of a HTTP GET you can also use a HTTP POST. The HTTP POST is send to the server. So you have to handle the request on your server-side with a simple servlet. This can be implemented as singelton and so be readable from your GWT-server-context. This method is a bit complex and brings a lot of work, since you then have to pass your information back to the GWT-client-context.

Which version is the best for you, depends on the details of your project. Usually I would say, that the Cookie-Version is the best.

0

精彩评论

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

关注公众号