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过 ...
随机推荐
- 重装Ubuntu系统并配置开发环境
安装 Ubuntu 并配置开发环境 写一篇文章详细记录下来所有的过程,以便以后参考. 安装前的准备 备份所有代码和配置文件 备份下载的各类文件 Ubuntu 安装 下载安装 Ubuntu14.04,下 ...
- JS获取select选中的值
var oSel=oFl.getElementsByTagName('select')[0]; oSel.onchange=function(){ var indexselect=oSel.selec ...
- 转: Linux C 动态内存分配 malloc及相关内容 .
一.malloc()和free()的基本概念以及基本用法: 1.函数原型及说明: void *malloc(long NumBytes):该函数分配了NumBytes个字节,并返回了指向这块内存的指针 ...
- 《STL源码剖析》环境配置
首先,去侯捷网站下载相关文档:http://jjhou.boolan.com/jjwbooks-tass.htm. 这本书采用的是Cygnus C++ 2.91 for windows.下载地址:ht ...
- IAR FOR ARM 各版本,需要的大家可以收藏了
原创,原帖地址是在阿莫论坛:http://www.amobbs.com/thread-5400051-1-1.html,这里也在博客贴上来供大家参考. 用过Keil和IAR,个人感觉是IAR还是很不错 ...
- DB_WRITER_PROCESSES与LOG_ARCHIVE_MAX_PROCESSES
DB_WRITER_PROCESSES Property Description Parameter type Integer Default value 1 or CPU_COUNT / 8, ...
- POJ2002 Squares(枚举)
题目链接. 分析: 普遍的做法是:先枚举两个点,通过数学公式得到另外2个点,使得这四个点能够成正方形.然后检查散点集中是否存在计算出来的那两个点,若存在,说明有一个正方形. 但这种做法会使同一个正方形 ...
- guid转int
如果你想生成一个数字序列,你将会获得一个19位长的序列. 下面的方法会把GUID转换为Int64的数字序列. private static long GenerateIntID() { ...
- 高效算法——G - 贪心
G - 贪心 Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Desc ...
- zoj 1372
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1372 #include<iostream> #include& ...