SPRINGMVC interceptors, do not block JSP files

Source: Internet
Author: User
Tags stub

Spring MVC interceptors only block controllers from intercepting JSP files, and if they do not intercept JSP files, they will also bring security issues to the system.

There are two types of solutions:

1, put all the JSP files into the Web-inf folder, so that users are directly unable to access the JSP file under the Web-inf file. The idea of spring MVC is also to request the relevant JSP page through the @requestmapping of the controller, rather than the user's direct access to the JSP page.

Then write the relevant configuration

Join in the Springmvc.xml

    <mvc:interceptors>        <Mvc:interceptor>            <mvc:mappingPath="/**"/>
<mvc:exclude-mappingPath= "/admin/login.do"/><!--Exclude blocked pages -- <Beanclass= "Com.ms.controller.LoginInterceptor"></Bean> </Mvc:interceptor> </mvc:interceptors>
 Public classLogininterceptorImplementsHandlerinterceptor { Public voidaftercompletion (httpservletrequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3) throwsException {//TODO auto-generated Method Stub    }     Public voidPosthandle (httpservletrequest arg0, HttpServletResponse arg1, Object arg2, Modelandview arg3)throwsException {//TODO auto-generated Method Stub    }     Public BooleanPrehandle (httpservletrequest req, httpservletresponse res, Object handler)throwsException {HttpSession session=req.getsession (); Object obj=session.getattribute ("UserId"); if(obj==NULL|| Obj.tostring (). Equals ("") {req.getrequestdispatcher ("/admin/login.do"). Forward (req, res); return false; }        return true; }}

On the Contoller floor

@Controller @requestmapping ("/admin")  Public class Admincontroller {            @RequestMapping ("/login")      public  String login () {         return "/web-inf/jsp/admin/login.jsp";    }}

The above can solve the Spring MVC interception jsp page problem

2, there is a solution: JSP if not placed under the Web-inf file, Spring MVC is unable to intercept, this situation requires the most primitive servlet filter interface, in particular, you can refer to

The following blog will not repeat.

http://blog.csdn.net/lsx991947534/article/details/45499205

SPRINGMVC interceptors, do not block JSP files

Related Article

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.