Thursday, December 14, 2006

Handling non-GWT POSTs in GWT servlets

Posted and answered my own question regarding Google Web Toolkit. The way to handle non-GWT POSTs in GWT servlet is to:
  • Override the service(...) method. If your servlet inherits from GWT's RemoteServiceServlet, you can't override doPost as RemoteServiceServlet has marked it final.
  • Figure out some way to distinguish a GWT POST from a non-GWT POST. The easiest way is to add a hidden field (i.e., ) and check for that parameter value in the service(...) method. If that parameter isn't there, then call super.service(...) so that GWT calls can go through.
  • Declared the servlet in MODULE.gwt.xml like any other servlet (GWT or not).

Since I use Instantiation's GWT Designer, it automatically generates the service's Async interface java file, implementation java file, and servlet entry in the MODULE.gwt.xml file. Thus all I do is add the service(...) method in the implementation file.

Cheers.
boscomonkey wrote:
> In our GWT app, we have a login dialog box that pops up to handle fresh
> users or users whose sessions have timed out. Now we wish to accept
> username/password POSTs from our static web site or even affiliate web
> sites. What are some approaches for handling POSTs from outside the GWT
> app?
> It seems that one simple approach is to write a standard servlet that
> implements doPost, place it in our GWT app's server package space, and
> if users authenticate properly, redirect to our GWT app's URL. In this
> case, do I have to map this servlet in our MODULE.gwt.xml? What's the
> URL to this servlet?

0 Comments:

Post a Comment

<< Home