getting an warning as“ [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping for GET /ProjectFE/”

后端 未结 1 740
栀梦
栀梦 2021-01-26 14:42

so as the title says I\'m getting an error a [org.springframework.web.servlet.PageNotFound] (default task-1) No mapping for GET /ProjectFE/ how should I fix this?

相关标签:
1条回答
  • 2021-01-26 15:15

    First of all arrange your web.xml like this

        <?xml version="1.0" encoding="UTF-8"?>
        <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    
    
        <!-- Processes application requests -->
        <servlet>
            <servlet-name>appServlet</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>appServlet</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>
    
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                WEB-INF/spring-config.xml
            </param-value>
        </context-param>
       <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    </web-app>
    

    As you are defining contex-param you don't need to use init-param same xml file. Now change a little in spring-config.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans:beans
    xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context.xsd">
    
    <mvc:annotation-driven/>
    
    <resources mapping="/resources/**" location="/resources/" />
    
    <beans:bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/Views/" />
        <beans:property name="suffix" value=".jsp" />
     </beans:bean>
    
      <context:component-scan    base-package="controller" />        
     </beans:beans>
    

    Look carefully in line <beans:property name="prefix" value="/Views/" />. Your folder name is Views but you defined view. That's why perhaps you are getting error.

    Give a shout if it works.

    0 讨论(0)
提交回复
热议问题