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过 ...
随机推荐
- STM32学习笔记——定时器中断(向原子哥学习)
定时器中断 STM32 的定时器功能十分强大,有 TIME1 和 TIME8 等高级定时器,也有 TIME2~TIME5 等通用定时器,还有 TIME6 和TIME7 等基本定时器.在本章中,我们将利 ...
- 关于C#的委托
作者 陈嘉栋(慕容小匹夫) 阅读目录 0x00 前言 0x01 从观察者模式说起 0x02 向Unity3D中的SendMessage和BroadcastMessage说拜拜 0x03 认识回调函数 ...
- Entity Framework OData filter inherit
过滤继承对象 TPH 的情况 EF : return Task.FromResult<IQueryable<Parent>>( query.OfType<ChildA&g ...
- 马云专访二:点评阿里雅虎交易、BAT三家、互联网巨头与政府关系
记者:我们不得不要说到你和雅虎之间的事情了.你知道,雅虎对整个互联网业的意义不只是一家公司,它有它象征的意义,重要的是,雅虎对阿里巴巴的意义更加非同寻常,当你最后决定用76亿美元从雅虎“赎身”的时候, ...
- 把CSV文件导入到SQL Server表中
保存数据库数据直接查询select * from tableName 在数据表格的左上角右击——将结果另存为选择路劲保存好的就是.csv格式的数据 有时候我们可能会把CSV中的数据导入到某个数据库的表 ...
- insert 加的锁
?INSERT sets an exclusive lock on the inserted row. This lock is an index-record lock, not a next-ke ...
- AlgorithmsI Programming Assignment 1: Percolation
3种版本的答案,第一种使用virtual top and bottom site, 但有backwash的问题,解决这个问题有两种方法: 1. 使用2个WQUUF, 但会增加memory. One f ...
- ZOJ-1508Intervals(差分约束)
题意: 有一个序列,题目用n个整数组合 [ai,bi,ci]来描述它,[ai,bi,ci]表示在该序列中处于[ai,bi]这个区间的整数至少有ci个.如果存在这样的序列,请求出满足题目要求的最短的序列 ...
- 2012 B 中国近现代史纲要》课程期末考试试卷
湖南人文科技学院2013年3月公共课 2011级<中国近现代史纲要>课程期末考试试卷B 考核方式:(开卷) 考试时量: ...
- [Locked] Strobogrammatic Number & Strobogrammatic Number II & Strobogrammatic Number III
Strobogrammatic Number A strobogrammatic number is a number that looks the same when rotated 180 deg ...