Announcement Announcement Module
Collapse
No announcement yet.
Spring 3 + Tiles 2 + (JSP, Freemarker, ...) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 3 + Tiles 2 + (JSP, Freemarker, ...)

    I have next situation. Guess I'm stupid with this code, but at all can not handle it myself.

    web.xml I need dispatcher servlet to handle requests from starting from root path (/*)
    Code:
    <servlet-mapping>
       <servlet-name>dispatcher</servlet-name>
       <url-pattern>/*</url-pattern>
    </servlet-mapping>
    I also would use Tiles.
    definitions.xml
    Code:
    <definition name="catalog.default" template="pages/home.jsp">
       <put-attribute name="header" value="pages/common/header.jsp" />
       <put-attribute name="menu" value="pages/common/menu.jsp" />
       <put-attribute name="footer" value="pages/common/footer.jsp" />
       <put-attribute name="search" value="pages/body/statistic-info.jsp" />
    </definition>
    servlet-context.xml
    Code:
    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
       <property name="definitions" value="/WEB-INF/definitions.xml"/>
    </bean>
    <bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
       <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
    </bean>

    my controller
    Code:
    @Controller
    public class HomeController {
    
        @RequestMapping(value = "/", method = RequestMethod.GET)
        public ModelAndView home() {
    
            ModelAndView mv = new ModelAndView();
    
            mv.setViewName("catalog.default");
    
            return mv;
        }
    
    }

    I've got
    Code:
    org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/pages/home.jsp] in DispatcherServlet with name 'dispatcher'
    Tried to configure in different ways and also not only with JSP.
    Also tried Freemarker with the same result.

    Looks like Spring view resolvers works only parallel, they could handle different views.
    But could not handle view after view.

    And all this only for <url-pattern>/*</url-pattern>.
    If I used diferent path (example: /test/*) all will works, this is because dispatcher servlet doesn't handle pages path.
    What I did wrong?
    How could I use url-path "/*" with tiles and pages?

    folder pages placed not in WEB-INF but in root directory.
    Code:
    project-home
     - js\
     - css\
     - pages\
     - WEB-INF\

  • #2
    try using
    Code:
    <servlet-mapping>
       <servlet-name>dispatcher</servlet-name>
       <url-pattern>/</url-pattern>
    </servlet-mapping>
    i.e. without the Asterisk ("*") in <url-pattern>. What i think the problem here is, is that your Tiles config correctly determines pages/home.jsp, but which then again maps the <url-pattern>/*</url-pattern>. The DispatcherSerlvet again dispatches this "request" and tries to resolve an appropriate RequestMapping/Controller for pages/home.jsp, which you have not defined (of course), and that's why Spring complains with the above error.

    When omitting the Asterisk in <url-pattern>, pages/home.jsp is not matched against this pattern, and so the servlet engine retrieves the JSP page and renders it. That's the same reason why <url-pattern>/test/*</url-pattern> worked.
    Last edited by rpelger; Nov 23rd, 2011, 08:59 AM.

    Comment

    Working...
    X