Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringMVC获取404错误_Java_Jsp_Spring Mvc_Tomcat - Fatal编程技术网

Java SpringMVC获取404错误

Java SpringMVC获取404错误,java,jsp,spring-mvc,tomcat,Java,Jsp,Spring Mvc,Tomcat,启动tomcat后,浏览器中出现404错误: 我输入localhost:8080/mvc/hello或localhost:8080/mvc/hello.jsp 但是如果我键入localhost:8080,这是正常的,可以访问: 在myspringmvcservlet.xml中: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"

启动tomcat后,浏览器中出现404错误:

我输入
localhost:8080/mvc/hello
localhost:8080/mvc/hello.jsp

但是如果我键入
localhost:8080
,这是正常的,可以访问:

在my
springmvcservlet.xml
中:

<?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:context="http://www.springframework.org/schema/context"   
 xmlns:mvc="http://www.springframework.org/schema/mvc" 
 xsi:schemaLocation="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-4.1.xsd  
 http://www.springframework.org/schema/mvc 
 http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> 
    <!-- scan the package and the sub package --> 
    <context:component-scan base-package="com.ypd.springmvcdemo"/>
    <!-- don't handle the static resource -->
    <mvc:default-servlet-handler />
    <!-- if you use annotation you must configure following setting -->
    <mvc:annotation-driven />
    <!-- configure the InternalResourceViewResolver -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">

        <property name="prefix" value="/WEB-INF/jsp/" />

        <property name="suffix" value=".jsp" />
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <!--configure the setting of springmvcDispatcherServlet and configure the mapping-->
   <servlet>
       <servlet-name>springmvc</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <init-param>
           <param-name>contextConfigLocation</param-name>
           <param-value>classpath:springmvc-servlet.xml</param-value>
       </init-param>
   </servlet>

    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
在my
web.xml
中:

<?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:context="http://www.springframework.org/schema/context"   
 xmlns:mvc="http://www.springframework.org/schema/mvc" 
 xsi:schemaLocation="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-4.1.xsd  
 http://www.springframework.org/schema/mvc 
 http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> 
    <!-- scan the package and the sub package --> 
    <context:component-scan base-package="com.ypd.springmvcdemo"/>
    <!-- don't handle the static resource -->
    <mvc:default-servlet-handler />
    <!-- if you use annotation you must configure following setting -->
    <mvc:annotation-driven />
    <!-- configure the InternalResourceViewResolver -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">

        <property name="prefix" value="/WEB-INF/jsp/" />

        <property name="suffix" value=".jsp" />
    </bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <!--configure the setting of springmvcDispatcherServlet and configure the mapping-->
   <servlet>
       <servlet-name>springmvc</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <init-param>
           <param-name>contextConfigLocation</param-name>
           <param-value>classpath:springmvc-servlet.xml</param-value>
       </init-param>
   </servlet>

    <servlet-mapping>
        <servlet-name>springmvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

编辑

日志看起来是正确的:

[2017-03-20 03:06:48255]工件SpringMVCDemo:战争爆发:服务器未连接。部署不可用。 已连接到目标VM,地址:'127.0.0.1:51764',传输:'socket' 2017年3月20日15:06:50.080 info[main]org.apache.catalina.startup.VersionLoggerListener.log服务器版本:apache Tomcat/9.0.0.M17 2017年3月20日15:06:50.085 info[main]org.apache.catalina.startup.VersionLoggerListener.log服务器构建时间:2017年1月10日20:59:20 UTC 2017年3月20日15:06:50.085 info[main]org.apache.catalina.startup.VersionLoggerListener.log服务器编号:9.0.0.0 2017年3月20日15:06:50.085 info[main]org.apache.catalina.startup.VersionLoggerListener.log操作系统名称:Mac OS X 2017年3月20日15:06:50.088 info[main]org.apache.catalina.startup.VersionLoggerListener.log操作系统版本:10.12.2 2017年3月20日15:06:50.089 info[main]org.apache.catalina.startup.VersionLoggerListener.log体系结构:x86_64 2017年3月20日15:06:50.089 info[main]org.apache.catalina.startup.VersionLoggerListener.log Java Home:/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home/jre 2017年3月20日15:06:50.089 info[main]org.apache.catalina.startup.VersionLoggerListener.log JVM版本:1.8.0_121-b13 2017年3月20日15:06:50.089 info[main]org.apache.catalina.startup.VersionLoggerListener.log JVM供应商:Oracle公司 2017年3月20日15:06:50.089 info[main]org.apache.catalina.startup.VersionLoggerListener.log catalina_BASE:/Users/jack/Library/Caches/IntelliJIdea2016.3/tomcat/tomcat_9_0_0_M17_SpringMVCDemo 2017年3月20日15:06:50.090 info[main]org.apache.catalina.startup.VersionLoggerListener.log catalina_HOME:/Users/jack/Library/Tomcat9 2017年3月20日15:06:50.091 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Djava.util.logging.config.file=/Users/jack/Library/Caches/IntelliJIdea2016.3/tomcat/tomcat_9_0_0_M17_SpringMVCDemo/conf/logging.properties 2017年3月20日15:06:50.091 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager 2017年3月20日15:06:50.091 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-agentlib:jdwp=transport=dt_socket,地址=127.0.0.1:51764,挂起=y,服务器=n 2017年3月20日15:06:50.091 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Dcom.sun.management.jmxremote= 2017年3月20日15:06:50.092 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Dcom.sun.management.jmxremote.port=1099 2017年3月20日15:06:50.093 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Dcom.sun.management.jmxremote.ssl=false 2017年3月20日15:06:50.093 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Dcom.sun.management.jmxremote.authenticate=false 2017年3月20日15:06:50.093 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Djava.rmi.server.hostname=127.0.0.1 2017年3月20日15:06:50.093 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Djdk.tls.ephemeralDHKeySize=2048 2017年3月20日15:06:50.093 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Djava.protocol.handler.pkgs=org.apache.catalina.webresources 2017年3月20日15:06:50.093 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Dcatalina.base=/Users/jack/Library/Caches/IntelliJIdea2016.3/tomcat/tomcat_9_0_0_M17_SpringMVCDemo 2017年3月20日15:06:50.094 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Dcatalina.home=/Users/jack/Library/Tomcat9 2017年3月20日15:06:50.094 info[main]org.apache.catalina.startup.VersionLoggerListener.log命令行参数:-Djava.io.tmpdir=/Users/jack/Library/Tomcat9/temp 2017年3月20日15:06:50.094信息[主要]org.apache.catalina.core.AprLifecycleListener.lifecycleEvent在java.library.path:/Users/jack/library/java/Extensions:/library/java/Extensions:/Network/library/java/Extensions:/System/library/java/Extensions:/usr/lib/java:,找不到允许在生产环境中实现最佳性能的基于APR的apache Tomcat本机库。 2017年3月20日15:06:50.527 info[main]org.apache.coyote.AbstractProtocol.init初始化ProtocolHandler[“http-nio-8080”] 2017年3月20日15:06:50.560 info[main]org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector使用用于servlet写入/读取的共享选择器 2017年3月20日15:06:50.563 info[main]org.apache.coyote.AbstractProtocol.init初始化ProtocolHandler[“ajp-nio-8009”] 2017年3月20日15:06:50.565 info[main]org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector使用用于servlet写入/读取的共享选择器 2017年3月20日15:06:50.581信息[main]org.apache.catalina.startup.catalina.load初始化在1455毫秒内处理 2017年3月20日15:06:50.709信息[main]org.apache.catalina.core.StandardService.startInternal启动服务catalina 2017年3月20日15:06:50.709 info[main]org.apache.catalina.core.standardeengine.start内部启动Servlet引擎:apache Tomcat/9.0.0.M17 2017年3月20日15:06:50.745 info[main]org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler[http-nio-8080] 2017年3月20日15:06:50.766信息[main]org.apache.coyote.AbstractProtocol.start Startin
<init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>classpath:springmvc-servlet.xml</param-value>
</init-param>
<init-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
<servlet>
       <servlet-name>springmvc</servlet-name>
       <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
       <init-param>
           <param-name>contextConfigLocation</param-name>
           <param-value>classpath:springmvc-servlet.xml</param-value>
       </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>