Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
请求的资源在spring mvc中不可用_Spring_Spring Mvc - Fatal编程技术网

请求的资源在spring mvc中不可用

请求的资源在spring mvc中不可用,spring,spring-mvc,Spring,Spring Mvc,我正在努力学习SpringMVC,并且面临一个问题(这似乎是一个常见的问题)。我已经找到了很多解决方案,但没有任何东西能帮我解决问题 我的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

我正在努力学习SpringMVC,并且面临一个问题(这似乎是一个常见的问题)。我已经找到了很多解决方案,但没有任何东西能帮我解决问题

我的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">
<display-name>Spring Hello World</display-name>
<welcome-file-list>
    <welcome-file>hello.jsp</welcome-file>
</welcome-file-list>

<listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

<servlet>
    <servlet-name>chatbooster</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>chatbooster</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
编辑1:


问题的出现是因为tomcat服务器,因为我的简单html页面也没有运行,并且它引发了相同的异常。我使用的是tomcat服务器版本7。有人能告诉我这个异常的原因吗?

Tomcat不知道hello.jsp,因为它在WEB-INF中

改变

<welcome-file-list>
    <welcome-file>hello.jsp</welcome-file>
</welcome-file-list>

hello.jsp


/

它会起作用。

这可能是Hello.jsp的一个例子。jsp的第一个字母是大写的,但是在控制器中,您返回的是小写的Hello。如果您将控制器更改为返回字符串“Hello”,它应该可以工作。

谢谢大家的回答。实际上,我可以通过将html和jsp页面的位置从web inf文件夹更改为web content文件夹来解决我的问题。我不知道它为什么会工作,但现在服务器正在运行页面。

您到底遇到了什么样的错误?您的控制器正在初始化吗?您的控制器方法是否被调用?如果你愿意接受你之前问题的一些答案,人们也会更愿意回答。对此我很抱歉……我会记住这一点。关于这个问题,问题似乎与tomcat服务器有关,因为即使是简单的html页面在服务器运行时也会显示相同的错误。你能给我提个建议吗?有什么问题吗?
   <%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="i" uri="http://java.sun.com/jsp/jstl/core" %> 
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     
 <html>
<head>
<title>Home</title>
</head>
<body>
 <h1>Hello World!</h1>

 <hr/>

  <form action="hi">
   Name: <input type="text" name="name"> <input type="submit" value="Submit">
   </form>

 </body>
 </html>
 @Controller
public class HelloWorldController {

@RequestMapping("/")
 public String hello() {
 return "hello";
 }

@RequestMapping(value = "/hi", method = RequestMethod.GET)
 public String hi(@RequestParam("name") String name, Model model) {
 String message = "Hi " + name + "!";
 model.addAttribute("message", message);
 return "hi";
}

}
<welcome-file-list>
    <welcome-file>hello.jsp</welcome-file>
</welcome-file-list>
<welcome-file-list>
    <welcome-file>/</welcome-file>
</welcome-file-list>