Use of interceptors, configure the H5 page for mobile browser access

Source: Internet
Author: User

Package Com.thinkgem.jeesite.modules.sys.interceptor;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.web.servlet.handlerinterceptor;import Org.springframework.web.servlet.modelandview;import Com.thinkgem.jeesite.common.service.baseservice;import Com.thinkgem.jeesite.common.utils.stringutils;import com.thinkgem.jeesite.common.utils.useragentutils;/** *  Mobile-Phone View blocker * @author * @version 2014-9-1 */public class Mobileinterceptor extends Baseservice implements Handlerinterceptor {@Overridepublic Boolean prehandle (httpservletrequest request, httpservletresponse response, Object handler) throws Exception {return true;} @Overridepublic void Posthandle (HttpServletRequest request, httpservletresponse response, Object handler, Modelandview Modelandview) throws Exception {if (Modelandview! = null) {//if the phone or tablet is accessed, jump to the Phone view page. if (Useragentutils.ismobileortablet (request) &&! Stringutils.startswithignorecase (Modelandview.getviewName (), "redirect:")) {Modelandview.setviewname ("mobile/" + Modelandview.getviewname ())}}} @Overridepublic void Aftercompletion (HttpServletRequest request, httpservletresponse response, Object handler, Exception ex) throws Exception {}}

Configuration file Spring-mvc.xml:

<!--interceptor configuration, intercept sequence: First executed, then defined, and finally executed at the first bit. --><mvc:interceptors><mvc:interceptor><mvc:mapping path= "${adminpath}/**"/><MVC: Exclude-mapping path= "${adminpath}/"/><mvc:exclude-mapping path= "${adminpath}/login"/><MVC: Exclude-mapping path= "${adminpath}/sys/menu/tree"/><mvc:exclude-mapping path= "${adminPath}/sys/menu/ Treedata "/><mvc:exclude-mapping path=" ${adminpath}/oa/oanotify/self/count "/><bean class=" Com.thinkgem.jeesite.modules.sys.interceptor.LogInterceptor "/></mvc:interceptor><!--phone view blocker-- <mvc:interceptor><mvc:mapping path= "/**"/><bean class= " Com.thinkgem.jeesite.modules.sys.interceptor.MobileInterceptor "/></MVC:INTERCEPTOR></MVC: Interceptors>

  

Use of interceptors, configure the H5 page for mobile browser access

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.