Sitemesh does not decorate the returned view

I will advise Sitemesh does not decorate the returned submissions , but this post does not work for me.

I hope that sitemesh will decorate the pages .jsp, but when one view is returned by the controller, it is not decorated.

This is part of mine web.xml:

  <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

This is mine decorators.xml:

<?xml version="1.0" encoding="UTF-8"?>    
<decorators>
    <decorator name="basicLayout" page="/WEB-INF/decorators/base_layout.jsp">
        <pattern>*.jsp</pattern>
    </decorator>
</decorators>

I use InternalResourceViewResolverto resolve my view on behalf of the logic to the actual path:

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    p:viewClass="org.springframework.web.servlet.view.JstlView"
    p:prefix="/WEB-INF/jsp/"
    p:suffix=".jsp" />

And this is my controller:

@Controller
public class UserController {
    @RequestMapping("/user/registration")
    public String registrationForm() {
        return "user/registration";
    }   
}

My page jsp /WEB-INF/jsp/user/registration.jsp. After I request user/registrationthis jsp page will not be decorated.

+4
source share
1 answer

Change your template to

<pattern>/*</pattern>

, RequestDispatcher#forward() InternalResourceViewResolver.

SiteMeshFilter forward ,

<filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>
+2

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


All Articles