首页 > 代码库 > SpringMVC - 问题. No mapping found for HTTP request with URI

SpringMVC - 问题. No mapping found for HTTP request with URI

  <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="http://www.mamicode.com/WEB-INF/html/" />
        <property name="suffix" value="http://www.mamicode.com/.html" />
    </bean>

这个配置用于SpringMVC跳转控制。

 

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

如果是静态资源如 css js html... 。InternalResourceViewResolver 不会解析资源,而是当作一个url被DispatcherServlet 拦截到..

@RequestMapping(value = "http://www.mamicode.com/")
    public String login() {
        return "login"; 
    }

localhost:8080/demo/login.html  这时就会报 No mapping found for HTTP request with URI

 

解决办法

  <mvc:default-servlet-handler/>