错误404页面未找到:RequestMapping无法正常工作

时间:2017-09-28 14:34:01

标签: spring-mvc

请问我可能会打扰某人,因为这个问题已经被问到了,但我检查了每一个答案,但我完全不理解为什么会遇到这个错误。

以下是dispatcher-servlet.xml的内容:

                      

<context:component-scan base-package="flopiano" />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
            <value>/WEB-INF/jsp/</value>
    </property>
    <property name="suffix">
            <value>.jsp</value>
    </property>
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager" />

    <mvc:annotation-driven />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/flopiano" />
        <property name="username" value="root" />
        <property name="password" value="" />
    </bean>

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="flopiano.entity" />
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        <property name="persistenceUnitName" value="flopiano" />
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">none</prop>
            </props>
        </property>
    </bean>

    <bean id="jpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="showSql" value="true" />
        <property name="generateDdl" value="true" />
        <property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

    <mvc:resources mapping="/resources/**" location="/WEB-INF/resources/" />
</beans>

这是web.xml文件内容

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- Declaration de la servlet de Spring et de son mapping -->
    <servlet>
        <servlet-name>servlet-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>servlet-dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <!-- Declaration de l'utilisation de la ressource JDBC -->
    <resource-ref>
        <description>Ressource JDBC de l'application</description>
        <res-ref-name>jdbc/dsMonApplication</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
</web-app>

这是控制器引用指定的URL:

@RequestMapping(value = "/login", method = RequestMethod.GET)
public String displayConnectionPage() {
    return "connection";
}

因此,点击带有锚点的按钮'我收到了404错误。

按钮代码:

<ul class="navbar-nav ml-auto">
    <li class="nav-item">
        <a class="nav-link js-scroll-trigger" style="color:#191970;" href="#about">ACCUEIL</a>
    </li>
    <li class="nav-item">
        <a class="nav-link js-scroll-trigger" style="color:#191970;" href="#services">PRESENTATION</a>
    </li>
    <li class="nav-item">
        <a class="nav-link js-scroll-trigger" style="color:#191970;" href="#contact">VIDEOS</a>
    </li>
    <li class="nav-item">
        <a class="nav-link js-scroll-trigger" style="color:#191970;" href="#contact">PHOTOS</a>
    </li>
    <li class="nav-item">
        <a class="nav-link js-scroll-trigger" style="color:#191970;" href="#contact">DEMANDER UN DEVIS</a>
    </li>
    <li class="nav-item">
        <a class="nav-link js-scroll-trigger" style="color:#191970;" href="#contact">CONTACT</a>
    </li>
    <li class="nav-item">
        <a class="nav-link js-scroll-trigger" style="color:#191970;" href="login">CONNEXION</a>
    </li>
</ul>

项目结构:

flopiano:
    

-src
-main
-java
-resources
-web-app
-WEB-INF/
-jsp
-connexion.jsp
-reources
-css
-js
-dispatcher-servlet.xml
-web.xml

0 个答案:

没有答案