2011-03-09 75 views
4

我的调度员servlet.xml中为什么我的JSP视图没有被解析?

<?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" 
     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.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
     <mvc:annotation-driven/> 
     <context:component-scan base-package="com.example" /> 

    <bean id="viewResolver" 
       class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
       p:prefix="/WEB-INF/views/" p:suffix=".jsp" p:viewClass="org.springframework.web.servlet.view.JstlView"/> 

</beans> 

这是我的控制器

package com.example.spring; 

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

@Controller 
public class HelloController { 

     @RequestMapping("/form.htm") 
     public ModelAndView hello(Model model) { 
       return new ModelAndView("index"); 
     } 
} 

我看到这在我的控制台时,我已经在调试应用程序。

WARNING: No mapping found for HTTP request with URI [/WEB-INF/views/index.jsp] in DispatcherServlet with name 'dispatcher' 

控制器被击中,并返回视图,但它不能被解析。

+0

你可以发布你的调度servlet的映射conf从web.xml – 2011-03-09 06:05:21

+2

看看这个问题:http://stackoverflow.com/questions/1266303/no-mapping-found-for-http-request-with-uri -web-inf-pages-apiform-jsp – Javi 2011-03-09 08:58:03

+0

你可以发布项目的结构和web.xml吗? – chris 2011-03-09 10:32:38

回答

3

听起来像是你可能会丢失以下在web.xml

<servlet> 
    <servlet-name>jsp</servlet-name> 
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class> 
</servlet> 

<servlet-mapping> 
    <servlet-name>jsp</servlet-name> 
    <url-pattern>/WEB-INF/views/*</url-pattern> 
</servlet-mapping> 

由于@Javi已经评论说,这是already answered here

+0

我无法从Spring的文档中推断出这一点。你有参考吗? – stevebot 2011-03-09 15:49:31

+2

我不确定你的web.xml是什么样的,但是假设你有一个映射到DispatcherServlet的'/'url模式。有一个[以前的答案](http://stackoverflow.com/questions/234210/can-anyone-explain-servlet-mapping/245143#245143)解释了servlet映射。基本上我认为JSP是通过DispatcherServlet路由的,因为没有明确的映射。上面的代码添加了将'/ WEB-INF/views /'下的所有内容都路由到'JspServlet'的映射。我想我得到了原始信息[这里](http://anders.com/projects/sysadmin/tomcat.html) – andyb 2011-03-09 16:10:20

1

将index.jsp添加到您的/ WEB-INF/views /目录中。

+1

我做了,仍然没有 – stevebot 2011-03-09 06:40:06

+0

@stevebot - 一切似乎都很好,请确保文件部署到服务器,并且不仅仅在你的开发环境中。 – Bozho 2011-03-09 09:12:00

相关问题