本文介绍了基于用户代理检测服务器上的GWT排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我目前正在为我的网络应用程序添加HTML5脱机支持,并且大部分都采用了与mgwt相同的方法: b 使用servlet根据浏览器的用户代理提供清单文件。 我的问题涉及步骤2:在我的servlet中,我想要检测为某个请求提供哪个置换。我现在这样做的方式是: 从请求中获取用户代理字符串 userAgent.contains(safari))映射到'agent id',我可以使用映射文件映射到换句话说,map Mozilla / 4.0(兼容; MSIE 6.0b; Windows NT 5.1)到 ie6 ,我可以将它映射(使用生成的映射文件,请参见下面的示例)至 15B454D690F2CCAD57F1DD809429BF42 。 < permutation name =15B454D690F2CCAD57F1DD809429BF42> < user.agent> ie6< /user.agent> < / permutation> 我面对的问题是:我想使用相同的链接方法用户代理字符串作为GWT使用的排列(即映射 Mozilla / 4.0(兼容; MSIE 6.0b; Windows NT 5.1)到 ie6 )。这样,当我的G时,我不必修复我的代码WT会根据其他排列/浏览器版本进行更新。换句话说,我不喜欢我当前解决方案,在我的排列映射中,将servlet中的完整用户代理字符串与用户代理id(在我的示例中为'ie6')进行天真匹配。 我想过的解决方案是:在页面加载之后,检测加载的排列,并将其作为参数传递给servlet。 。然后,在获取该置换的清单后,使用javascript将其作为html标记的属性插入。但是,动态插入它似乎不能正常工作。 (请参阅动态触发HTML5缓存清单文件?)(同一篇文章解释了使用iframe动态执行此操作的解决方法,但我更喜欢更清晰的解决方案) 以某种方式使用客户端将完整的用户代理字符串映射到我的servlet中的置换。我更喜欢这个解决方案,但还没有找到一种方法来实现这一点... GWT使用JavaScript来实现这一点(请参阅 UserAgentPropertyGenerator )。 我可以在我的servlet中执行此操作,但此javascript方法不仅使用用户代理,而且还使用dom文档... 是否有其他解决方案我忽略?当然其他人也必须在创建HTML5清单文件时遇到这个问题... 您可以利用随 HTML5Manifest 解决方案, //www.m-gwt.com/rel =nofollow> mgwt 。他们有一个链接器,它产生一个可以被 servlet ,然后根据用户代理头文件返回适当的缓存文件。 如果你想自己做,你可以根据http user-agent头和 compilation-mappings.txt找出每个浏览器最合适的排列方式。 code> gwt编译器生成的文件,如果您使用 xsiframe 链接器。 I'm currently working on adding HTML5 offline support to my web application, and am mostly following the same approach of mgwt:Generate manifest files per permutation at compulation timeUsing a servlet to serve the manifest file, based on the user-agent of the browser.My question involves step 2: In my servlet, I want to detect which permutation to serve for a certain request. The way I do this now is:Get the user agent string from the requestMap this (using simple string operations (e.g. userAgent.contains("safari")) to the 'agent id', which I can map using a mapping file to the permutation strong name. In other words, map Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1) to ie6, which I can map (using the generated mapping file, see example below) to 15B454D690F2CCAD57F1DD809429BF42. <permutation name="15B454D690F2CCAD57F1DD809429BF42"> <user.agent>ie6</user.agent></permutation>The problem I'm facing: I want to use the same method of linking a user agent string to a permutation as GWT uses (i.e. map Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1) to ie6). This way I don't have to fix my code whenever my GWT gets updated with other permutations/browser versions. In other words, I don't like my current solution of naively matching the complete user agent string in the servlet with the user agent 'id' (in my example 'ie6') in my permutation mapping.The solutions I thought about were:after page load, detect the loaded permutation, and pass that as argument to the servlet. Then after fetching the manifest for that permutation, insert that as an attribute of the html tag using javascript. However, inserting this dynamically does not seem to work properly. (See Dynamically Trigger HTML5 Cache Manifest file? ) (the same post explains a workaround of doing this dynamically using an iframe, but I prefer a cleaner solution)somehow use the client-side to map the complete user agent string to a permutation, in my servlet. I'd prefer this solution, but havent found a way to do achieve this... GWT uses javascript to achieve this (see UserAgentPropertyGenerator).I could execute this in my servlet, but this javascript method not only uses the user agent, but uses the dom document as well...Are there other solutions I am overlooking? Surely others must have had this issue as well when creating HTML5 manifest files... 解决方案 You can take advantage of the HTML5Manifest solution provided with mgwt. They have a linker which produces a file which can be read by the servlet they provide, and return the appropriate list of files to cache by the browser based on the user-agent header.If you want to do it by yourself, you can figure out the most suitable permutation per browser, based on the http user-agent header, and on the compilation-mappings.txt file which is generated by the gwt compiler if you are using xsiframe linker. 这篇关于基于用户代理检测服务器上的GWT排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-14 21:42