Return different GWT imlementation to Mobile and D

2019-04-16 14:04发布

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?

3条回答
再贱就再见
2楼-- · 2019-04-16 14:19

Have you looked at the MobileWebApp sample from GWT?

查看更多
一纸荒年 Trace。
3楼-- · 2019-04-16 14:30

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.

查看更多
再贱就再见
4楼-- · 2019-04-16 14:38

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.

查看更多
登录 后发表回答