Springmvc configures the servlet interception form/* And/, springmvcservlet

Source: Internet
Author: User

Springmvc configures the servlet interception form/* And/, springmvcservlet

Today, I copied an existing spring-mvc project to modify the configuration as a new project. The result is a tragedy! Having encountered a small problem that had plagued me for a long time, I was not able to deal with it after finding a colleague and looking for a director. After a long time, I finally found the problem. I just wrote it down. What's better about a good memory than a bad blog!

Problem description:

The project is very simple, just to build a spring-mvc Framework and write a test NewsController. The configuration of the problem is as follows:

Web. xml

 1 <servlet> 2     <servlet-name>spring-mvc</servlet-name> 3     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 4     <init-param> 5       <param-name>contextConfigLocation</param-name> 6       <param-value>/WEB-INF/spring-mvc.xml</param-value> 7     </init-param> 8   </servlet> 9   <servlet-mapping>10     <servlet-name>spring-mvc</servlet-name>11     <url-pattern>/*</url-pattern>12   </servlet-mapping>

The view parser of spring-mvc is as follows:

<! -- View interpretation class: pass a View name to a View through the configuration file to process InternalResourceViewResolver. Added JSTL support --> <bean id = "viewResolver" class = "org. springframework. web. servlet. view. internalResourceViewResolver "> <property name =" prefix "value ="/WEB-INF/views/"/> <property name =" suffix "value = ". jsp "/> </bean>

The controller method is as follows:

// Homepage @ RequestMapping ("/index") public String getnewsList (ModelMap model) {return "ttt ";}

Ttt. jsp is a new ttt under the/WEB-INF/views/directory. jsp, then start the project, access the project http: // localhost: 8080/news/index, the result returns 404, Problem accessing/news/WEB-INF/views/ttt. jsp.

Solution

  At first, I thought that the jsp page was not compiled, and finally found that it was not compiled. tomcat's jsp was compiled at the first request page, but why didn't it be compiled? Indicates that no request has been sent to the page. You can view the information printed on the console.

Log print does not find/WEB-INF/views/ttt. jsp corresponding handler, description/WEB-INF/views/ttt. the jsp request was intercepted twice by spring-mvc's selvet. Why? The reason is that the interception form configured in web. xml/* is above, and modification to/is OK.

To sum up

/* It intercepts all requests, including the. jsp page that jumps after view resolution,/it does not intercept the. jsp page after view resolution!

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.