404 error occurred on the SPRINGMVC access page

Source: Internet
Author: User

Error configuring SPRINGMVC: I added <!--springmvc in Web. config-<servlet> <servlet-name>springmvc</   Servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!--springmvc-xml configuration file--<init-param> <param-name>contextConfigLocation</param-name> &lt ;p aram-value>classpath:springmvc-servlet.xml</param-value> </init-param> <!--execution order-<l oad-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name> Springmvc</servlet-name><url-pattern>/*</url-pattern></servlet-mapping>
Configure the SPRINGMVC project, 1. Start tomcat without error, access to the page through the Controller method, always prompt for 404 errors. The prompt path is: The project name/xxx.jsp (the page is in the Webroot root directory) found the path is not wrong. 2. Access to index.jsp is still a hint of 404 error. 3. At the method breakpoint in the controller, debug can come in, so the controller class is scanned in Springmvc. 5.MyEclipse Console without error, when accessing the page the console outputs: Warning: No mapping found for HTTP request with URI [/springecharts001/radio1.jsp] in Dispatch Erservlet with Name ' SPRINGMVC ' when you see no mapping, think it will be in Web. xml <servlet-mapping> error, so will <servlet-mapping> <servlet-name>springMvc</servlet-name><url-pattern>/*</url-pattern></servlet-mapping>
Change to <servlet-mapping> <servlet-name>springMvc</servlet-name><url-pattern>/</url-pattern>&LT;/SERVLET-MAPPING&GT, restart the server, and then visit the page to find that it was really successful.
here, the difference between/and/* is raised.

Answer address:http://m.blog.csdn.net/blog/liuxiao723846/43733287the difference between/and/*:
< Url-pattern >/</url-pattern > does not match to *.jsp, that is: *.jsp does not enter spring's Dispatcherservlet class.
< Url-pattern >/* </url-pattern > matches *.jsp,The Dispatcherservlet class, which returns to the spring when the JSP view is returned, causes the corresponding controller to be found so that the 404 error is reported.

In summary, a little knowledge of URL mapping for Web. XML:
<url-pattern>/</url-pattern> will match a path URL such as/login, and will not match a suffix URL with a pattern of *.jsp
<url-pattern>/*</url-pattern> matches all URLs: path-type and suffix-type URLs (including/login,*.jsp,*.js and *.html, etc.)


http://www.iteye.com/problems/95145

1, defined in the Tomcat\conf\web.xml

Java code1.<servlet>2.<servlet-name>default</servlet-name>3.<servlet-class>org.apache.catalina.servlets.defaultservlet</servlet-class> 4.<init-param>5.<param-name>debug</param-name>6.<param-value>0</param-value>7.</init-param>8.<init-param>9.<param-name>listings</param-name>10.<param-value>false</param-value>11.</init-param>12.<load-on-startup>1</load-on-startup>13.</servlet>
<!--the mapping for the default servlet ---
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

that is, by default, the function is if, its primary function is to read the stream back if the request is coming up as a static resource such as HTML/CSS/JS.

In addition, a similar interception of all *.jsp
Java code1.<servlet>2.<servlet-name>jsp</servlet-name>3.<servlet-class>org.apache.jasper.servlet.jspservlet</servlet-class>4.<init-param>5.<param-name>fork</param-name>6.<param-value>false</param-value>7.</init-param>8.<init-param>9.<param-name>xpoweredBy</param-name>10.<param-value>false</param-value>11.</init-param>12.<load-on-startup>3</load-on-startup>13.</servlet>
<!--the mapping for the JSP servlet ---
<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>jsp</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>


if the Springmvc intercept is/that replaces the default, then this time we can use the
<mvc:default-servlet-handler/>----> Delegate to the default
<!--static resource mapping --
<mvc:resources mapping= "/images/**" location= "/web-inf/images/"/>
Seehttp://jinnianshilongnian.iteye.com/blog/1423971 

arbitrary mapping of static resources.
http://blog.sina.com.cn/s/blog_534f69a00101332u.html

No mapping found for HTTP request with URI

This problem occurs because the configuration is wrong in Web. XML, such as:

<servlet>
<servlet-name>springMVCDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springMVC-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVCDispatcherServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

When you return a path in control, it takes the path (/view/index.jsp) as a request to be intercepted by Dispatcherservlet. So the exception is thrown, there are two ways to solve it:

First, even if the interception of Dispatcherservlet to add suffixes such as: *.do;

In this way, the JSP suffix will not intercept.

The second method is to add a spring-servlet.xml:

<mvc:default-servlet-handler/>


There is still doubt, who can not add?

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

404 error occurred on the SPRINGMVC access page

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.