找不到带有URI的HTTP请求的映射[/HelloWeb/WEB-INF/jsp/hello.jsp]

时间:2013-08-13 08:16:11

标签: spring spring-mvc

我尝试使用简单的jsp加载一个简单的spring mvc示例,但失败并出现以下错误: 没有找到带URI的HTTP请求的映射[/ HelloWeb / WEB-INF / jsp / hello的.jsp] 我正在使用Spring 3.2.2。 我非常感谢你的帮助。 我尝试了几件事,但似乎我无法在控制器中映射我的jsp页面。

web.xml 看起来像这样:

<web-app id="WebApp_ID" version="2.4"
               xmlns="http://java.sun.com/xml/ns/j2ee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>

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

  <servlet-mapping>
    <servlet-name>HelloWeb</servlet-name>
    <url-pattern>*.jsp</url-pattern>
  </servlet-mapping>
</web-app>

HelloWeb-servlet.xml 看起来像这样:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   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="com.tutorial.spring" />

  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
  </bean>
</beans>

HelloControll.class 看起来像这样:

package com.tutorial.spring;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping("/hello")
public class HelloController {
  @RequestMapping(method= RequestMethod.GET)
  public String printHello(ModelMap modelMap) {
    modelMap.addAttribute("message", "Hello Spring MVC Framework!");

    return "hello";
  }
}

6 个答案:

答案 0 :(得分:1)

用于点击printHello处理程序方法的正确网址

/HelloWeb/hello.jsp 

答案 1 :(得分:1)

我明白了。愚蠢的错误。 我用资本'H'命名我的jsp“Hello.jsp”,并在我的控制器'hello'中以小写字母返回。

刚刚将我的jsp页面改为“hello.jsp”。

感谢您的帮助。

答案 2 :(得分:0)

像这样修改web.xml

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

尝试访问/ YourAppName / hello。然后Spring-MVC将触发方法printHello()。然后返回/ WEB-INF / jsp /.

中的jsp视图

答案 3 :(得分:0)

调度程序servlet必须映射正确的主路径:

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

答案 4 :(得分:0)

按照servlet

中的定义将jsp文件移动到正确的位置

<强> / WEB-INF / JSP /

答案 5 :(得分:0)

正确的URL为http://localhost:8080/hello,不带“ / HelloWeb”