找不到HTTP请求的映射,无法转到servlet调度程序

时间:2017-02-02 10:36:05

标签: maven spring-mvc

我收到错误,只显示索引欢迎页面。点击或导航到另一个页面后,它显示如下错误。我正在使用具有所有正确依赖性的Maven。

控制器类:

@Controller
public class HelloController {

    @RequestMapping(value = "/welcome", method = RequestMethod.GET)
    public ModelAndView helloworld(Model model1) {
        System.out.println("HelloController");
        ModelAndView model = new ModelAndView("HelloPage");
        model.addObject("msg", "hello World");
        return model;

    }
}

的index.jsp

<html>
<body>
    <h1>First Spring MVC Application Demo</h1>
    <a href="welcome">click here to cgreatting msg</a>
</body>
</html>

**web.xml**

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-servlet.xml</param-value>
    </context-param>
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
</web-app>

弹簧调度

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!--controller and services scan -->

     <context:component-scan base-package="controller.HelloController" /> 


    <!--To specify the view components -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>

</beans>


**HelloPage.jsp**
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
    <h1>First Spring MVC Application Demo</h1>

    <h2>${msg}</h2>

</body>
</html>

错误

Feb 02, 2017 3:52:54 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:SpringMVC-1' did not find a matching property.
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/9.0.0.M17
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Jan 10 2017 20:59:20 UTC
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         9.0.0.0
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Linux
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            4.4.0-59-generic
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             /usr/lib/jvm/java-8-openjdk-amd64/jre
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         /home/bridgeit/Anuj/Spring-MVC workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         /home/bridgeit/apache-tomcat-9.0.0.M17
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=/home/bridgeit/Anuj/Spring-MVC workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=/home/bridgeit/apache-tomcat-9.0.0.M17
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=/home/bridgeit/Anuj/Spring-MVC workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=/home/bridgeit/apache-tomcat-9.0.0.M17/endorsed
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=UTF-8
Feb 02, 2017 3:52:54 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib/x86_64-linux-gnu/jni:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/usr/lib/jni:/lib:/usr/lib
Feb 02, 2017 3:52:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Feb 02, 2017 3:52:54 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Feb 02, 2017 3:52:54 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Feb 02, 2017 3:52:54 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Feb 02, 2017 3:52:54 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 404 ms
Feb 02, 2017 3:52:54 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Feb 02, 2017 3:52:54 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/9.0.0.M17
Feb 02, 2017 3:52:55 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Feb 02, 2017 3:52:55 PM org.apache.catalina.core.ApplicationContext log
INFO: No Spring WebApplicationInitializer types detected on classpath
Feb 02, 2017 3:52:55 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Feb 02, 2017 3:52:55 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
Feb 02, 2017 3:52:55 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Thu Feb 02 15:52:55 IST 2017]; root of context hierarchy
Feb 02, 2017 3:52:55 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/spring-servlet.xml]
Feb 02, 2017 3:52:55 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 336 ms
Feb 02, 2017 3:52:55 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [http-nio-8080]
Feb 02, 2017 3:52:55 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [ajp-nio-8009]
Feb 02, 2017 3:52:55 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1394 ms

HTTP Status 404 - /SpringMVC-1/welcome

type Status report

message /SpringMVC-1/welcome

description The requested resource is not available.

Apache Tomcat/9.0.0.M17

0 个答案:

没有答案