Filter过滤器实现同一地址手机和电脑页面不同

String[] mobileAgents = { “iphone”, “android”, “phone”, “mobile”,
“wap”, “netfront”, “java”, “opera mobi”, “opera mini”, “ucweb”,
“windows ce”, “symbian”, “series”, “webos”, “sony”,
“blackberry”, “dopod”, “nokia”, “samsung”, “palmsource”, “xda”,
“pieplus”, “meizu”, “midp”, “cldc”, “motorola”, “foma”,
“docomo”, “up.browser”, “up.link”, “blazer”, “helio”, “hosin”,
“huawei”, “novarra”, “coolpad”, “webos”, “techfaith”,
“palmsource”, “alcatel”, “amoi”, “ktouch”, “nexian”,
“ericsson”, “philips”, “sagem”, “wellcom”, “bunjalloo”, “maui”,
“smartphone”, “iemobile”, “spice”, “bird”, “zte-“, “longcos”,
“pantech”, “gionee”, “portalmmm”, “jig browser”, “hiptop”,
“benq”, “haier”, “^lct”, “320×320”, “240×320”, “176×220”,
“w3c “, “acs-“, “alav”, “alca”, “amoi”, “audi”, “avan”, “benq”,
“bird”, “blac”, “blaz”, “brew”, “cell”, “cldc”, “cmd-“, “dang”,
“doco”, “eric”, “hipt”, “inno”, “ipaq”, “java”, “jigs”, “kddi”,
“keji”, “leno”, “lg-c”, “lg-d”, “lg-g”, “lge-“, “maui”, “maxo”,
“midp”, “mits”, “mmef”, “mobi”, “mot-“, “moto”, “mwbp”, “nec-“,
“newt”, “noki”, “oper”, “palm”, “pana”, “pant”, “phil”, “play”,
“port”, “prox”, “qwap”, “sage”, “sams”, “sany”, “sch-“, “sec-“,
“send”, “seri”, “sgh-“, “shar”, “sie-“, “siem”, “smal”, “smar”,
“sony”, “sph-“, “symb”, “t-mo”, “teli”, “tim-“, “tosh”, “tsm-“,
“upg1”, “upsi”, “vk-v”, “voda”, “wap-“, “wapa”, “wapi”, “wapp”,
“wapr”, “webc”, “winw”, “winw”, “xda”, “xda-“,
“Googlebot-Mobile” };
/**
* 判断是否是手机访问
*
* @param request
* @return
*/
public boolean isMoblie(HttpServletRequest request) {
boolean isMoblie = false;
String[] mobileAgents = { "iphone", "android", "phone", "mobile",
"wap", "netfront", "java", "opera mobi", "opera mini", "ucweb",
"windows ce", "symbian", "series", "webos", "sony",
"blackberry", "dopod", "nokia", "samsung", "palmsource", "xda",
"pieplus", "meizu", "midp", "cldc", "motorola", "foma",
"docomo", "up.browser", "up.link", "blazer", "helio", "hosin",
"huawei", "novarra", "coolpad", "webos", "techfaith",
"palmsource", "alcatel", "amoi", "ktouch", "nexian",
"ericsson", "philips", "sagem", "wellcom", "bunjalloo", "maui",
"smartphone", "iemobile", "spice", "bird", "zte-", "longcos",
"pantech", "gionee", "portalmmm", "jig browser", "hiptop",
"benq", "haier", "^lct", "320x320", "240x320", "176x220",
"w3c ", "acs-", "alav", "alca", "amoi", "audi", "avan", "benq",
"bird", "blac", "blaz", "brew", "cell", "cldc", "cmd-", "dang",
"doco", "eric", "hipt", "inno", "ipaq", "java", "jigs", "kddi",
"keji", "leno", "lg-c", "lg-d", "lg-g", "lge-", "maui", "maxo",
"midp", "mits", "mmef", "mobi", "mot-", "moto", "mwbp", "nec-",
"newt", "noki", "oper", "palm", "pana", "pant", "phil", "play",
"port", "prox", "qwap", "sage", "sams", "sany", "sch-", "sec-",
"send", "seri", "sgh-", "shar", "sie-", "siem", "smal", "smar",
"sony", "sph-", "symb", "t-mo", "teli", "tim-", "tosh", "tsm-",
"upg1", "upsi", "vk-v", "voda", "wap-", "wapa", "wapi", "wapp",
"wapr", "webc", "winw", "winw", "xda", "xda-",
"Googlebot-Mobile" };
if (request.getHeader("User-Agent") != null) {
for (String mobileAgent : mobileAgents) {
if (request.getHeader("User-Agent").toLowerCase()
.indexOf(mobileAgent) >= 0) {
isMoblie = true;
break;
}
}
}
return isMoblie;
}
public class WapFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
response.setContentType("text/html;charset=utf-8");
HttpServletRequest httpRequest = (HttpServletRequest) request;
String uri = httpRequest.getRequestURI();
if (isMoblie(httpRequest)) {
httpRequest.getRequestDispatcher("/wap" + uri).forward(request,
response);
} else {
chain.doFilter(request, response);// 电脑放行
}
}
//省略其他代码……
}
<filter>
<filter-name>wapfilter</filter-name>
<filter-class>cn.dtblog.filter.WapFilter</filter-class>
</filter><filter-mapping>
<filter-name>wapfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
电脑地址 | 拼接wap后的手机网址 |
/index.jsp | /wap/index.jsp |
/about.jsp | /wap/about.jsp |
原文由博主 乐智 编辑撰写,版权归博主所有。
原文地址 http://www.dtblog.cn/1105.html 转载请注明出处!
Filter过滤器实现同一地址手机和电脑页面不同的更多相关文章
- 用sublime server 启动本地服务器(手机访问电脑页面)
安装sublime server 插件包 1.Ctrl + shift + p install package ...
- SpringBoot+Shiro学习(七):Filter过滤器管理
SpringBoot+Shiro学习(七):Filter过滤器管理 Hiwayz 关注 0.5 2018.09.06 19:09* 字数 1070 阅读 5922评论 1喜欢 20 先从我们写的一个 ...
- Filter(过滤器)学习
一.Filter简介 Filter也称之为过滤器,它是Servlet技术中最激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态 ...
- 安卓手机与电脑无线传输文件(利用ftp服务)
安卓手机与电脑无线传输文件(利用ftp服务) 手机与电脑无线传输文件,手机开启ftp服务,电脑能够对手机内全部文件进行全方位管理,包括上传.下载.新建.删除等,而且手机和电脑能够双向传输,很方便.手机 ...
- WIFI环境下Android手机和电脑通信
前面已经写过一篇java实现最基础的socket网络通信,这篇和之前那篇大同小异,只是将客户端代码移植到手机中,然后获取本机IP的方法略有不同. 先讲一下本篇中用到Android studio的使用吧 ...
- 手机访问电脑wampServer本地环境页面
1. 电脑需要安装好wamp,我这里用的2.0版本,下载地址 http://pan.baidu.com/s/1jG31hbS 2. 电脑需要有个wifi,我用的360wifi 3. 启动 ...
- JavaWeb(五)Filter过滤器
Filter过滤器 Fileter介绍 Filter也称之为过滤器,它是Servlet技术中最实用的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Serv ...
- SpringBoot使用Filter过滤器处理是否登录的过滤时,用response.sendRedirect()转发报错
1.使用response.sendRedirect("/login")时报错,控制台报错如下: Cannot call sendError() after the response ...
- java使用Filter过滤器对Response返回值进行修改
转:java使用Filter过滤器对Response返回值进行修改 练习时只做了对request 的处理,这里记录一下,filter 对 response的处理. 原文地址:java使用Filter过 ...
随机推荐
- python【第二篇】列表、元组、字典及文件操作
本节内容 列表 元组操作 字符串操作 字典操作 集合操作 文件操作 字符编码与转码 1.列表 列表是我们最以后最常用的数据类型之一,通过列表可以对数据实现最方便的存储.修改等操作:列表有序.可变.元素 ...
- Mosquitto-MQTT
安装Mosquitto #To use the new repository you should first import the repository package signing key: w ...
- net programming guid
Beej's Guide to Network Programming Using Internet Sockets Brian "Beej Jorgensen" Hallbeej ...
- MIT教授将网页开发整合为完整独立的程式语言Ur/Web
MIT 的软体技术教授 Adam Chlipala 设计了新的 Ur/Web 程式语言,这是一个整合 HTML.CSS.XML.SQL 及 JavaScript 等网路标准的“完整独立”语言,强调快速 ...
- Hybrid UI framework shootout: Ionic vs. Famo.us vs. F7 vs. OnsenUI
1 Introduction In the past 2 years I’ve been working intensively on mobile applications, mostly hybr ...
- Ferry Loading||
uva10440:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&am ...
- ZABBIX作集中式NGINX性能监控的注意要点
今天测试好了.但有几个要点要注意. 一是出了问题看日志. 二是主动测试脚本. 三是注意LLD自动发现的ZABBIX类型(TRAPPER,捕捉器类型) 四是有主机上有问题时可以看到(UNSUPPORT) ...
- Delphi重载,覆盖,多态
一.override 重载 type TFigure = class procedure Draw; virtual;//(我的理解是)父类中可以使用父类的,子类中使用子类的.与“四”是有区别的. e ...
- 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)
题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...
- 【数学】CSU 1810 Reverse (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1810 题目大意: 一个长度为N的十进制数,R(i,j)表示将第i位到第j位翻转过来后的 ...