views:

315

answers:

3

Hi people, 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!

A: 

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
A: 

Joaquín L. Robles Thanks for ur answer! It works perfectly for me too. I am using Spring mvc 3.0.3 and Tiles 2.2.2

Paganini
A: 
<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