Spring MVC中没有请求的资源

Sub*_*bho 14 java spring jsp spring-mvc

我是Spring MVC的新手,我正在尝试在其中部署一个hello world应用程序.但是我总是在jsp页面上得到一个请求的资源不可用错误.我正在使用tomcat 7.这里我粘贴我的代码任何人请帮助..

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"
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>HelloWorldSpring</display-name>
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

为spring-servlet.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd">


<context:component-scan
    base-package="net.viralpatel.spring3.controller" />

<bean id="viewResolver"
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass"
        value="org.springframework.web.servlet.view.JstlView" />
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
</bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

应用程序的控制器

package net.viralpatel.spring3.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloWorldController {

    @RequestMapping("/hello")
    public ModelAndView helloWorld() {
        String message = "Hello World, Spring 3.0!";
        System.out.println(message);
        return new ModelAndView("hello", "message", message);
    }

}
Run Code Online (Sandbox Code Playgroud)

为hello.jsp

<html>
<head>
<title>Spring 3.0 MVC </title>
</head>
<body>
${message}
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

的index.jsp

<html>
<head>

</head>
<body>
<a href="hello">Say Hello</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我的应用程序,我还添加了我的项目结构的截图..在此输入图像描述

Roh*_*han 9

主要问题是 <url-pattern>*.html</url-pattern>.
我在您的代码中进行了以下更改,我可以在我的机器上运行相同的代码:

1)更改<url-pattern>*.html</url-pattern><url-pattern>/</url-pattern>
2)复制jstl-1.2.jarlib文件夹中.