Results 1 to 4 of 4

Thread: View resolvers include context in path

  1. #1
    Join Date
    Aug 2006
    Posts
    24

    Default View resolvers include context in path

    Hello,
    I'm trying to develop a simple MVC app to understand how everything is put together.

    I've a problem in the line of this thread:
    http://forum.springsource.org/showth...apping-problem

    The fact being that depending on url-pattern I use in web.xml while the correct method of the controller is called correctly, the view that is looked for changes, addind in some cases the context path to it.

    For example, with this patterns:
    Code:
      <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>*.html</url-pattern>
      </servlet-mapping>
    Everything works fine, and (for example) to a certain request the jsp view used is "/WEB-INF/jsp/test.jsp".
    While if I use:
    Code:
      <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/dir/*</url-pattern>
      </servlet-mapping>
    The view that Spring tries to use becomes: "/mywebapp/WEB-INF/jsp/test.jsp" that of course is wrong.

    On the before mentioned thread you can see the error (mine is completely the same):
    Code:
    09:52:26 WARN  org.springframework.web.servlet.PageNotFound[noHandlerFound] - No mapping for [/myspringmvc/WEB-INF/view/index.jsp] in DispatcherServlet with name 'webapp'
    Any hint on why this strange behavior?

    I know that as a workaround I can map / to the dispatcher, but I really would like to understand the issue, it seems like a bug to me.

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,629

    Default

    Post your configuration... Never had this problem (neither with *.html or /app/* mappings). ...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Aug 2006
    Posts
    24

    Default

    Here are the relevant bits.

    dispatcher controller:
    Code:
    <?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:aop="http://www.springframework.org/schema/aop"
           xmlns:tx="http://www.springframework.org/schema/tx"
           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-3.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
           ">
    
      <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
            p:viewClass="org.springframework.web.servlet.view.JstlView"
            p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />
    
      <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
          <props>
            <prop key="/index.htm">indexController</prop>
          </props>
        </property>
      </bean>
        
      <bean name="indexController"
            class="org.springframework.web.servlet.mvc.ParameterizableViewController"
            p:viewName="index" />
        
    </beans>
    applicationContext:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans
      xmlns="http://www.springframework.org/schema/beans"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:p="http://www.springframework.org/schema/p"
      xmlns:aop="http://www.springframework.org/schema/aop"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:jpa="http://www.springframework.org/schema/data/jpa"
      xsi:schemaLocation="
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        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/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
    ">
    
      <context:annotation-config />
      <context:component-scan base-package="it.nibbles.airjb.controllers"/>
      <mvc:annotation-driven/>
    
      <bean id="localeResolver" class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver" />
      <bean id="messageSource" class="it.nibbles.airjb.i18n.JdbcMessageSource" p:codePrefix=":airjb:"
            p:autocreateUnknownKeys="true" />
      
    </beans>
    and web.xml:
    Code:
      <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
    (just one dispatcher)
    Using instead the pattern:
    <url-pattern>/*</url-pattern>
    exibits the beforementioned behavior, rendering impossible for me to render views (no view is ever found)
    Last edited by adusty; Jun 19th, 2012 at 03:39 PM.

  4. #4
    Join Date
    Aug 2006
    Posts
    24

    Default

    Would a complete example (a project from scratch, zipped) help for having help on the subject...?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •