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

당신은 web.xml의 디스패처 서블릿 매핑 매핑을 게시 할 수 있습니까 –

+2

이 질문을보십시오 : http://stackoverflow.com/questions/1266303/no-mapping-found-for-http-request-with-uri -web-inf-pages-apiform-jsp – Javi

+0

프로젝트의 구조와 web.xml을 게시 할 수 있습니까? – chris

답변

3

는 소리,이 already answered here입니다.

+0

나는 이것을 스프링의 문서에서 추측 할 수 없었다. 레퍼런스가 있으십니까? – stevebot

+2

web.xml의 모양이 확실하지 않지만'/'URL 패턴이 DispatcherServlet에 매핑되어 있다고 가정합니다. 서블릿 매핑을 설명하는 [이전 답변] (http://stackoverflow.com/questions/234210/can-anyone-explain-servlet-mapping/245143#245143)이 있습니다. 기본적으로 명시적인 매핑이 없기 때문에 JSP가 DispatcherServlet을 통해 라우팅되고 있다고 생각합니다. 위의 코드는'/ WEB-INF/views /'아래의 모든 것을'JspServlet'으로 라우팅하는 매핑을 추가합니다. 나는 원래 정보 [여기] (http://anders.com/projects/sysadmin/tomcat.html)가 있다고 생각한다. – andyb

1

/WEB-INF/views/디렉토리에 index.jsp를 추가하십시오. @Javi 이미 주석으로 당신이 당신의 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> 

에 다음을 누락 될 수 있습니다처럼

+1

아니요, 여전히 아무것도 아니요 – stevebot

+0

@stevebot - 모두 문제가없는 것으로 보입니다. 파일이 서버, 그리고 귀하의 dev에 env에서만되지 않습니다. – Bozho

관련 문제