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过 ...
随机推荐
- CentOS 6.4编译安装淘宝web服务器Tengine
Tengine 是由淘宝核心系统部基于Nginx开发的Web服务器,它在Nginx的基础上,针对大访问量网站的需求,添加了很多功能和特性.Tengine的性能和稳定性已经在大型的网站如淘宝网,淘宝商城 ...
- Laravel框架——增删改查
增: //save返回true false $res = new member(); res->username = 'a'; $res->password = 'b'; dd($res- ...
- 转:100个高质量Java开发者博客
原文来自于:http://www.importnew.com/7469.html ImportNew注:原文中还没有100个.作者希望大家一起来推荐高质量的Java开发博客,然后不段补充到这个列表.欢 ...
- BZOJ 1055 玩具取名
Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使 ...
- [BZOJ 3110] [Zjoi2013] K大数查询 【树套树】
题目链接: BZOJ - 3110 题目分析 这道题是一道树套树的典型题目,我们使用线段树套线段树,一层是区间线段树,一层是权值线段树.一般的思路是外层用区间线段树,内层用权值线段树,但是这样貌似会很 ...
- Solr4.6从数据库导数据的步骤
http://blog.csdn.net/bruce128/article/details/17796705 Solr4.6有从数据库导数据的功能.导入步骤如下: 1.将下载下来的solr4.6的di ...
- 延长FLASH和EEPROM芯片写入次数的小方法
开发电子产品时,常常需要断电后保存某些数据,这就需要使用 FLASH或EEPROM芯片,这两种芯片,可擦除的次数是有限制的,通常FLASH为10万次,EEPROM要多一点,为100万甚至1000万次. ...
- 【HDOJ】2699 Five in a Row
wa了几次,至少要考虑4个方向:下.右.左下.右下.很像当年北航的机试题目. /* 2699 */ #include <iostream> #include <cstdio> ...
- [C++关键字] alignof & alignas 内存对齐 sizeof 占内存大小
直接上代码测试是入门神器,以结构体为例,解释“对齐”和“补齐”概念. #include <iostream> struct Empty {}; struct Foo { int f2; d ...
- docs
https://www.eucalyptus.com/docs/eucalyptus/3.4/index.html [Eucalyptus PDF官方下载] http://aws.amazon.co ...