2016-06-03 18 views
0

StackOverflow에서 비슷한 질문을 여러 번 시도했지만 실제로 이해할 수 없었습니다! 이것은 첫 번째 Spring 응용 프로그램이므로 중복되는 질문에 대해서는 유감입니다. 어떤 도움이라도 대단히 감사 할 것입니다. 나는 다음과 같은 오류를 받고 있어요javax.servlet.ServletException : 이름이 'travel'인 서블릿에서 'hotels/booking/enterBookingDetails'라는 이름의 뷰를 확인할 수 없습니다.

나는 enterDetails 페이지를 탐색 할 때 : - :

@RequestMapping(value = "hotels/booking", method = RequestMethod.GET) 
public String bookingDetails(@RequestParam Long hotelId, Model model) {  
    Booking booking = bookingService.createBooking(hotelId,"keith"); 
    model.addAttribute(booking); 
    return "hotels/booking/enterBookingDetails"; 
} 

서블릿-context.xml에

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
     http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> 

    <!-- Configures the Spring MVC @Controller programming model --> 
    <annotation-driven /> 

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory --> 
    <resources mapping="/resources/**" location="/resources/" /> 

    <!-- Configures a handler for serving static resources by forwarding to the Servlet container's default Servlet. --> 
    <default-servlet-handler /> 

    <!-- Maps view names to Tiles Definitions with support for partial re-rendering --> 
    <beans:bean id="viewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver"> 
     <beans:property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/> 
    </beans:bean> 

    <!-- Initializes the Apache Tiles CompositeView system --> 
    <beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> 
     <beans:property name="definitions"> 
      <beans:value> 
       /WEB-INF/**/tiles.xml 
      </beans:value> 
     </beans:property> 
    </beans:bean> 

    <!-- Configures Spring Web FLow 
    <beans:import resource="webflow.xml" /> --> 

    <!-- Configures transaction management around @Transactional components --> 
    <tx:annotation-driven /> 

    <!-- Imports the application controllers that process client requests --> 
    <beans:import resource="controllers.xml" /> 


</beans:beans> 

-

여기
Exception thrown by application class 'org.springframework.web.servlet.DispatcherServlet.render:1029' 
javax.servlet.ServletException: Could not resolve view with name 'hotels/booking/enterBookingDetails' in servlet with name 'travel' 
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1029) 
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817) 
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719) 
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644) 
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) 
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290) 
at [internal classes] 
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) 
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:207) 
at [internal classes] 

는 컨트롤러의 'FROM'페이지 : -

,111,

enterBookingDetails.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> 
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> 

<div id="bookingForm"> 
    <div class="span-5"> 
     <h3>${booking.hotel.name}</h3> 

     <address> 
      ${booking.hotel.address} 
      <br/> 
      ${booking.hotel.city}, ${booking.hotel.state}, ${booking.hotel.zip} 
      <br/> 
      ${booking.hotel.country} 
     </address> 
     <p> 
      Nightly rate: <spring:bind path="booking.hotel.price">${status.value}</spring:bind> 
     </p> 
    </div> 
. 
. 
. 

web.xml을

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>classpath:/META-INF/spring/root-context.xml</param-value> 
    </context-param> 

    <!-- Creates the Spring Container shared by all Servlets and Filters --> 
    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <!-- Enables use of HTTP methods PUT and DELETE --> 
    <filter> 
     <filter-name>httpMethodFilter</filter-name> 
     <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class> 
    </filter> 

    <filter-mapping> 
     <filter-name>httpMethodFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

    <!-- Secures the application 
    <filter> 
     <filter-name>springSecurity</filter-name> 
     <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
     <init-param> 
      <param-name>targetBeanName</param-name> 
      <param-value>springSecurityFilterChain</param-value> 
     </init-param> 
    </filter> 

    <filter-mapping> 
     <filter-name>springSecurity</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping>--> 

    <!-- Handles all requests into the application --> 
    <servlet> 
     <servlet-name>travel</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <init-param> 
      <param-name>contextConfigLocation</param-name> 
      <param-value>classpath:/META-INF/spring/travel/servlet-context.xml</param-value> 
     </init-param> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 

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

</web-app> 

예약/

tiles.xml
<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE tiles-definitions PUBLIC 
    "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" 
    "http://tiles.apache.org/dtds/tiles-config_2_1.dtd"> 

<tiles-definitions> 

    <definition name="enterBookingDetails" extends="standardLayout"> 
     <put-attribute name="body" value="/WEB-INF/views/hotels/booking/enterBookingDetails.jsp"/> 
    </definition> 

    <definition name="reviewBooking" extends="standardLayout"> 
     <put-attribute name="body" value="/WEB-INF/views/hotels/booking/reviewBooking.jsp" /> 
    </definition> 

</tiles-definitions> 

프로젝트 탐색기 - enter image description here

+0

당신의 JSP 파일이 프로젝트 구조에있는 장소를 포함한다면 도움이 될 수 있습니다. – mugua

+0

뷰의 정의와 함께 관련 tile.xml을 게시 할 수 있습니까? – rptmat57

+0

월요일 아침에 둘 다 올리겠습니다! 나는 그 (것)들을 포스트에서 포함하지 않기 위하여 저로 어리 석었다 !! – bOgGaRt

답변

3

저는 여기에서 새로 왔지만 봄봄의 MVC 프로젝트에 참여했습니다. 그래서 나는 당신의 문제를 해결하는데 기여하기를 희망합니다. 당신은 다음과 같은 작업을 수행 할 수 있도록

가 나는의 ModelAndView 객체와 함께 작동 할 수 있도록 컨트롤러를 바꿀 것 :

@RequestMapping(value = "hotels/booking", method = RequestMethod.GET) 
    public ModelAndView bookingDetails(@RequestParameter Long hotelId) { 

    ModelAndView model = new ModelAndView("enterBookingDetails"); 
    Booking booking = bookingService.createBooking(hotelId,"keith"); 
    model.addObject("booking", booking); 
    return model; 
} 
+0

답변 해 주셔서 감사합니다. 방금 ​​시도했지만 불행히도 나는 여전히 똑같은 오류가 발생했습니다! – bOgGaRt

+1

죄송합니다. 코드에서 실수를 저질렀습니다. 그래서 변경했습니다. 나는 또한 "hotels/booking/enterBookingDetails"로 뷰를 호출하고 있음을 알았지 만, 이미 경로를 선언 했으므로 타일을 사용하고 있기 때문에 이름을 호출하기 만하면됩니다. – AlieneilA

+0

또는보기 해결을위한 bean이 필요합니다. – AlieneilA