2011-03-09 77 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

相關問題