UrlBasedViewResolver and Apache Tiles2 in Spring 3

I have the following exception when 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 looks like this:

<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 places in / app, it works fine, for example / app / welcome or / app / clientes, but this error appears when trying to open / app / clientes / something. I assume this has something to do with the URL Resolver, but I cannot find that ...

The My ClientesController class annotated with @Controller has the following method:

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

My JSP view files are located in / WEB -INF / views, for example:

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

Thank!

+3
3

styles.xml :

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

( ) ?

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

StackOverFlow, (type = "template" ):

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

I have not tested it, but as the documentation says: tile tile patterns

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

So try with two asterisks

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

Source: https://habr.com/ru/post/1760137/


All Articles