网站不同格式页面跳转的解决方案

时间: 2020-12-09 11:24 关注度: 149

网站不同格式页面跳转的解决方案

PC端和手机端入口一致,跳转不同页面的方法;PC端接口请求后跳转到jsp页面,手机端请求接口后跳转到html页面,两个客户端公用一个入口(index.do)。 // 跳转首页 @RequestMapping(value ="/index.do", method = RequestMethod.GET) public String toIndex(HttpServletRequestreq, HttpServletResponse res) { if(EquipmentJudgment.JudgeIsMoblie(req)) { // 来自移动端访问 return"redirect:/wap";//重定向到另一个接口(手机端接口入口) } else { // 来自PC端访问 return"/index";//跳转到index页面 } }1. spring-mvc.xml中修改视图解析器,如下: 说明:当接口返回页面时,首先会去找.html页面,找到了就执行完了,找不到就会自动去找.jsp页面。见HtmlResourceView.java 。所有的页面名字不要重复!2. 编写类EquipmentJudgment.java(判断是否是手机端) package com.abc.common; import javax.servlet.http.HttpServletRequest; public class EquipmentJudgment { public static booleanJudgeIsMoblie(HttpServletRequest request) { boolean isMoblie = false; String[] mobileAgents = {"iphone", "android", "phone", "mobile","wap", "netfront", "java", "operamobi", "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", "jigbrowser", "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; } }3. 编写类spring-mvc.xml 配置中的类HtmlResourceView.java(判断要跳转的页面是否存在) package com.abc.common; import java.io.File; import java.util.Locale; import org.springframework.web.servlet.view.InternalResourceView; public class HtmlResourceView extends InternalResourceView { @Override public boolean checkResource(Localelocale) { File file = newFile(this.getServletContext().getRealPath("/") + getUrl()); return file.exists();// 判断该页面是否存在 } }根据不同访问设备跳转到PC页面或手机页面方法;目前很多网站都是采用了响应式自适应页面的设计了,根据访问设备的不同,显示不同的内容。但是还是会有一些节奏比较慢的网站,还是PC页面和手机PAD页面不同的访问域名。第一个: var userAgent = navigator.userAgent.toLowerCase(); var platform; if(userAgent == null || userAgent == ''){ platform = 'WEB' ; }else{ if(userAgent.indexOf("android") != -1 ){ platform = 'ANDROID'; location.; }elseif(userAgent.indexOf("ios") != -1 ||userAgent.indexOf("iphone") != -1 ||userAgent.indexOf("ipad") != -1){ platform = 'IOS'; location.; }else if(userAgent.indexOf("windows phone") != -1 ){ platform = 'WP'; location.; }else{ platform = 'WEB' ; location.; } }直接上代码,修改代码中你的PC页面和手机页面地址即可。第二个:这一个是两段代码,分别放到PC页面网页和手机页面网页,实现不同设备访问不同页面都能实现调整,比如电脑访问了手机页面的地址也会跳转到PC页面上来。首先是放入PC页面的代码: var url = window.location.pathname;varwapurl="http://3g.xxx.com"+urlif(/AppleWebKit.*Mobile/i.test(navigator.userAgent)|| (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){ if(window.location.href.indexOf("?mobile")下边是放入手机页面的代码: var url = window.location.pathname;varpcurl="http://www.xxx.com"+urlif(/AppleWebKit.*Mobile/i.test(navigator.userAgent)==false||(/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))==false){ if(window.location.href.indexOf("?mobile")

漂亮的邻居电影完整版,我把女闺蜜摸到高潮了,久久电影网,在线观看av,chinesemature老熟妇oldman
成人用具| videosgrati欧美另类| 熟妇人妻引诱中文字幕| 呦女精品| 欧美zooz人禽交| 国产真实露脸精彩对白| 黄三级高清在线播放| 口碑最好的国产奶粉| 日本不无在线一区二区三区| 男女啪祼交视频| 8x永久华人成年免费| 中文无码欲求不满的人妻| 欧美高清videossex0ts| 办公室激烈叫床戏视频| 无码中文字幕av免费放| av天堂网2014| 苍老师免费av在线播放| 欧美viboss高清| 日本一区二区高清av中文| chinese中年熟妇free| 2020人妻中文字幕在线乱码| 免费a毛片| 老师在上课时露出奶头| 欧美z0z0人与物物| 在线黄色网站| 朋友的姐姐2| 加勒比一本大道香蕉大在线| 欧美高清vivoes69| 巨大垂乳日本熟妇| 某医院女厕美女如厕vod视频| <文本链> <文本链> <文本链> <文本链> <文本链> <文本链> http://m.cctn123.com http://m.d3rec.com http://www.hanesLamp.com http://www.cslsabie.com http://m.zhangwenjuanLawyer.com <文本链> http://m.cnditron.cn http://m.jw0513.com http://m.dogertime.com http://www.jsqiyou.com http://m.barfourstars.com <文本链> http://www.lianhuamachine.com http://m.yingzhe.org http://m.szhonghua.com http://m.htkj-cd.com http://m.syjtfw.com