GAE上的Mobile和Desktop客户端返回不同的GWT插件 [英] Return different GWT imlementation to Mobile and Desktop clients on GAE

查看:96
本文介绍了GAE上的Mobile和Desktop客户端返回不同的GWT插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的GWT应用程序(从GAE运行)中为桌面和移动客户端使用不同的实现。一种解决方案是GWT中的用户代理检测。这个解决方案将Desktop和Mobile实现加载到客户端中。

更清晰的解决方案是在服务器servlet上进行用户代理检测。此解决方案仅返回客户端的正确实施。



如何从GAE返回这个不同的实现?

我已经做到了。您将欢迎页面声明为映射为servlet的url

 < welcome-file-list> 
< welcome-file> / urlToSomeServlet< / welcome-file>
< / welcome-file-list>

在这个servlet中,你得到了userAgent的值:

 字符串userAgent = request.getHeader(User-Agent); 

然后,根据该值,您可以转发或重定向到您的桌面页面或您的移动页面:

  request.getRequestDispatcher(desireedHtmlPage.html)。forward(request,response); 

  response.sendRedirect是( desireedHtmlPage.html); 

转发会使浏览器认为他仍处于初始请求状态,并且仍会显示欢迎页面网址,而做重定向会实际上告诉浏览器他被重定向到另一个资源,所以资源的URL将显示在导航栏中。


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?

解决方案

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.

这篇关于GAE上的Mobile和Desktop客户端返回不同的GWT插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆