3

I've got the following exception while trying to open the URL http://localhost:8080/app/clientes/agregar:

javax.servlet.ServletException: Could not resolve view with name 'clientes/agregar' in servlet with name 'Spring MVC Dispatcher Servlet'

My mvc-config.xml is the following:

<mvc:annotation-driven />

<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</bean>

<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <property name="definitions" value="/WEB-INF/tiles/tiles.xml" />
</bean>

My simple tiles.xml:

<definition name="mainTemplate" template="/WEB-INF/template/template.jsp">
       <put-attribute name="titulo" value="Simple Tiles 2 Example" type="string" />
       <put-attribute name="header" value="/WEB-INF/template/header.jsp" />
       <put-attribute name="footer" value="/WEB-INF/template/footer.jsp" />
 </definition>

 <definition name="*" extends="mainTemplate">
   <put-attribute name="content" value="/WEB-INF/views/{1}.jsp" />
 </definition>

When I try to open locations under /app it works fine, like /app/welcome or /app/clientes, but this error appears when trying to open /app/clientes/something. I guess it has something to do with the URL Resolver, but I can't find what...

My ClientesController class, annotated with @Controller has a method like the following:

@RequestMapping(method = RequestMethod.GET, value = "agregar")
public void agregar() { ... }

My JSP view files are located under /WEB-INF/views like:

/WEB-INF/views
-- /clientes
---- agregar.jsp
-- welcome.jsp
-- clientes.jsp

Thanks!

Joaquín L. Robles
  • 6,261
  • 10
  • 66
  • 96

3 Answers3

1

Added the following in my tiles.xml and works fine:

<definition name="*/*" extends="mainTemplate">
    <put-attribute name="content" value="/WEB-INF/views/{1}/{2}.jsp" />
</definition>

Any better (more flexible) solution?

Joaquín L. Robles
  • 6,261
  • 10
  • 66
  • 96
1
<definition name="/**" extends="page">
    <put-attribute name="content" value="/WEB-INF/jsp/{1}.jsp"/>
</definition>

If you'll get StackOverFlow you should do like this (type="template"):

<put-attribute name="some_name" value="some_page.jsp" type="template"/>
proximo
  • 11
  • 1
1

I haven't tested it, but as the documentation says here: tiles wildcards

  • one asterisk (*) for a single placeholder;
  • two asterisks (**) to say "in every directory under the specified one";

So try with two asterisks

<definition name="**" extends="mainTemplate">
    <put-attribute name="content" value="/WEB-INF/views/{1}.jsp" />
</definition>
Javi
  • 19,387
  • 30
  • 102
  • 135