问题
I'm using different implementations for Desktop and Mobile clients in my GWT application (which runs from GAE). One solution is the user-agent detection in GWT. This solutions loads both the Desktop and Mobile implementation into the client.
A cleaner solution would be an user-agent detection on the server servlet. This solution only returns the correct implementation for the client.
How do I return this different implementations from GAE?
回答1:
I've actually done that. You declare your welcome page as an url that is mapped to as servlet
<welcome-file-list>
<welcome-file>/urlToSomeServlet</welcome-file>
</welcome-file-list>
In this servlet you get the userAgent value:
String userAgent = request.getHeader("User-Agent");
And then, depending on that value, you can either forward or redirect to your desktop page or to your mobile page:
request.getRequestDispatcher("desireedHtmlPage.html").forward(request,response);
or
response.sendRedirect("desireedHtmlPage.html");
Forward will make the browser think that he's still at the initial request and it will still display the welcome page url, while doing a redirect will actually tell the browser that he's being redirected to another resource, so that resource's url will be displayed in the navigation bar.
回答2:
Have you looked at the MobileWebApp sample from GWT?
回答3:
There's also a good example here GWT 2.1 Seminar 2010. This uses server side user-agent checking dropping back to query parameters (m=1). It does this in the applications gwt.xml file.
来源:https://stackoverflow.com/questions/7793883/return-different-gwt-imlementation-to-mobile-and-desktop-clients-on-gae