请求的资源不可用。运行spring mvc程序在eclipse与tomcat [英] The requested resource is not available.on running spring mvc program on eclipse with tomcat

查看:6181
本文介绍了请求的资源不可用。运行spring mvc程序在eclipse与tomcat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行基本的spring mvc程序,但是当我运行我得到上述错误

I was trying to run the basic spring mvc program but when i run i get the above mentioned error

HTTP Status 404 - 

--------------------------------------------------------------------------------

type Status report

message 

description The requested resource is not available.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.35

控制台日志是

Jun 13, 2017 12:50:01 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre7\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Java\jdk1.7.0\bin;C:\Program Files\Java\jdk1.8.0_65\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\RailsInstaller\Git\cmd;C:\RailsInstaller\Ruby2.3.0\bin;C:\Users\ADMIN\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\ADMIN\AppData\Local\Programs\Python\Python36-32\;C:\Users\ADMIN\AppData\Roaming\npm;D:\Softwares\eclipse\eclipse;
Jun 13, 2017 12:50:01 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:FirstSpringMVCProject' did not find a matching property.
Jun 13, 2017 12:50:01 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-9999"]
Jun 13, 2017 12:50:01 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jun 13, 2017 12:50:01 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1458 ms
Jun 13, 2017 12:50:02 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 13, 2017 12:50:02 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.35
Jun 13, 2017 12:50:08 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9999"]
Jun 13, 2017 12:50:08 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 13, 2017 12:50:08 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6638 ms

web.xml文件如下

web.xml file is as follows

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>FirstSpringMVCProject</display-name>
  <servlet>
    <servlet-name>spring-dispatcher</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
  </servlet>

  <servlet-mapping>
  <servlet-name>spring-dispatcher</servlet-name>
  <url-pattern>/</url-pattern>
  </servlet-mapping>
  </web-app>

内容如下

<bean xmlns="https://www.springframework.org/schema/beans"
        xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="https://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

        <bean id="HandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
        <bean name="/welcome.html" class="com.rohit.hellocontroller.HelloController"/>

        <bean id="viewResolver" class ="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix">

        <value>/WEB-INF/</value>
        </property>

        <property name="suffix">

        <value>.jsp </value>

        </property>

        </bean>




        </bean>

这是我的hellocontroller类文件

here is my hellocontroller class file

package com.rohit.hellocontroller;
 import javax.servlet.http.*;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
public class HelloController  extends AbstractController{


    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest arg0,
            HttpServletResponse arg1) throws Exception {

        ModelAndView modelview= new ModelAndView("HelloPage");
        modelview.addObject("welcomeMessage","Hi there user this is my own written message");

        return modelview;
    }

}

这里是我的类路径栈


i不要以为tomcat服务器的运行有问题,因为控制台日志显示为启动。仍然不明白为什么资源不能找到.....任何帮助将是伟大的

i dont think there is a problem with the running of tomcat server because console log shows it as started.Still cant figure out why the resource can't be located..... Any help would be great

控制台登录击中url

console log on hitting url

Jun 14, 2017 10:19:09 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre7\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Java\jdk1.7.0\bin;C:\Program Files\Java\jdk1.8.0_65\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\RailsInstaller\Git\cmd;C:\RailsInstaller\Ruby2.3.0\bin;C:\Users\ADMIN\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\ADMIN\AppData\Local\Programs\Python\Python36-32\;C:\Users\ADMIN\AppData\Roaming\npm;D:\Softwares\eclipse\eclipse;
Jun 14, 2017 10:19:09 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:FirstSpringMVCProject' did not find a matching property.
Jun 14, 2017 10:19:09 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-9999"]
Jun 14, 2017 10:19:09 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jun 14, 2017 10:19:09 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1130 ms
Jun 14, 2017 10:19:10 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jun 14, 2017 10:19:10 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.35
Jun 14, 2017 10:19:16 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-9999"]
Jun 14, 2017 10:19:16 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jun 14, 2017 10:19:16 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 6669 ms
Jun 14, 2017 10:19:52 AM org.apache.coyote.ajp.AjpMessage processHeader
SEVERE: Invalid message received with signature 18245
Jun 14, 2017 10:19:55 AM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: Invalid command 'GET / HTTP/1.1' received
Jun 14, 2017 10:20:05 AM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: read: 
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at org.apache.catalina.core.StandardServer.await(StandardServer.java:478)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:766)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:712)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456)

Jun 14, 2017 10:20:05 AM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: Invalid command '' received
Jun 14, 2017 10:20:07 AM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: Invalid command 'GET / HTTP/1.1' received
Jun 14, 2017 10:20:11 AM org.apache.coyote.ajp.AjpMessage processHeader
SEVERE: Invalid message received with signature 18245
Jun 14, 2017 10:20:17 AM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: read: 
java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at org.apache.catalina.core.StandardServer.await(StandardServer.java:478)
    at org.apache.catalina.startup.Catalina.await(Catalina.java:766)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:712)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:322)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:456)

Jun 14, 2017 10:20:17 AM org.apache.catalina.core.StandardServer await
WARNING: StandardServer.await: Invalid command '' received


推荐答案

spring-dispatcher.xml

<bean name="/welcome.html" class="com.rohit.hellocontroller.HelloController"/>

HelloController 中更新以下内容:

@Controller
public class HelloController{
      @RequestMapping("/")
      public ModelAndView handleRequestInternal(HttpServletRequest arg0,
                    HttpServletResponse arg1) throws Exception {
               return new ModelAndView("HelloPage","welcomeMessage","Hi there user this is my own written message");

            }
    }

这篇关于请求的资源不可用。运行spring mvc程序在eclipse与tomcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆