[SPRING] sitemesh 및 봄 MVC 데코레이터 패턴 문제
SPRINGsitemesh 및 봄 MVC 데코레이터 패턴 문제
나는 스프링 작업으로 sitemesh를 가지고 있는데, 이것은 설정이다 : decorator.xml
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/styles">
<excludes>
<pattern>/exclude.jsp</pattern>
<pattern>/exclude/*</pattern>
</excludes>
<decorator page="application/themeManager/theme.jsp" name="dos">
<pattern>/*</pattern>
</decorator>
</decorators>
그리고 이것은 내 web.xml입니다.
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<!-- The master configuration file for this Spring web application -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/config/web-application-config.xml
</param-value>
</context-param>
<!-- Enables Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Agregamos el filtro de sitemesh que permite interceptar todas las llamadas que necesitamos -->
<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>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<!-- Loads the Spring web application context -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Serves static resource content from .jar files such as spring-faces.jar -->
<servlet>
<servlet-name>Resources Servlet</servlet-name>
<servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<!-- Map all /resources requests to the Resource Servlet for handling -->
<servlet-mapping>
<servlet-name>Resources Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all *.spring requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
이 작업은 decorator.xml에서 패턴을 변경했을 때와 비슷합니다.
<decorator page="application/themeManager/theme.jsp" name="dos">
<pattern>/spring/cliente/index</pattern>
</decorator>
그것은 작동하지 않습니다, 나는 많은 조합을 시도하고 아무것도. 그런 다음 web.xml에서 스프링 서블릿에 대한 매핑을 다음과 같이 변경합니다.
스프링 MVC 디스패처 서블릿
* .htm
다음과 같이 새 패턴을 정의하십시오.
<데코레이터 페이지 = "application / themeManager / theme.jsp"name = "dos">
해결법
-
==============================
1.문제는 SiteMesh가 Request.getServletPath ()를 사용하여 스프링 MVC 응용 프로그램에서 모든 것을 "/ spring"으로 반환한다는 것입니다. 필자는 com.opensymphony.module.sitemesh.DecoratorMapper 인터페이스를 구현하고이를 일반 ConfigDecoratorMapper 대신 사용하여이 사실을 발견했습니다. 그런 다음 데코레이터를 요청에 매핑하는 데 사용되는 다양한 인수를 검사 할 수있었습니다. 불행히도 DispatcherServelet 매핑이나 그 변형에서 * .html 접미사를 사용하는 유일한 옵션 만 남게 될 것이라고 생각합니다.
문제는 SiteMesh가 Request.getServletPath ()를 사용하여 스프링 MVC 응용 프로그램에서 모든 것을 "/ spring"으로 반환한다는 것입니다. 필자는 com.opensymphony.module.sitemesh.DecoratorMapper 인터페이스를 구현하고이를 일반 ConfigDecoratorMapper 대신 사용하여이 사실을 발견했습니다. 그런 다음 데코레이터를 요청에 매핑하는 데 사용되는 다양한 인수를 검사 할 수있었습니다. 불행히도 DispatcherServelet 매핑이나 그 변형에서 * .html 접미사를 사용하는 유일한 옵션 만 남게 될 것이라고 생각합니다.
또 다른 옵션은 PageDecoratorMapper를 구성하고 원래의 장식되지 않은 페이지에서이 태그를 사용하여 사용할 레이아웃을 지정하는 것입니다.
<meta name="decorator" content="layoutName" />
그럼에도 불구하고 URL 매핑의 이점은 무효화됩니다.
-
==============================
2.나는 그 정확한 문제를 가졌다. 웹 서버에서 지정한 url 경로의 일부가 Spring으로 전달되기 전에 웹 서버에서 제거되지만 끝 부분에 와일드 카드를 사용하는 경우에만 발생합니다. 이미 www.myapp.com/spring/cliente/index.html이라는 URL을 web.xml에 넣었을 때이를 발견했습니다.
나는 그 정확한 문제를 가졌다. 웹 서버에서 지정한 url 경로의 일부가 Spring으로 전달되기 전에 웹 서버에서 제거되지만 끝 부분에 와일드 카드를 사용하는 경우에만 발생합니다. 이미 www.myapp.com/spring/cliente/index.html이라는 URL을 web.xml에 넣었을 때이를 발견했습니다.
<servlet-mapping> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <url-pattern>/spring/*</url-pattern> </servlet-mapping>
Spring은 / spring 다음에 요청 경로의 일부만 볼 것이다. 이 경우 RequestMapping을 "/cliente/index.html"로 지정해야합니다.
이 방법으로 서블릿 매핑을 지정할 수도 있습니다.
<servlet-mapping> <servlet-name>Spring MVC Dispatcher Servlet</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>
그러면 Spring은 전체 요청 경로를보고 "/spring/cliente/index.html"과 같은 요청 매핑을 지정할 수 있습니다. Sitemesh도 마찬가지입니다. 웹 서버가 통과하는 것만 볼 수 있습니다.
-
==============================
3.어쩌면 그것은 누군가에게 유용 할 것이고, 나는 동일한 문제를 가지고있다. 그리고 구글과 stem sitemesh 소스에 대한 연구 후에 ConfigDecoratorMapping을 확장함으로써 문제를 해결할 것이다. 여기 있습니다:
어쩌면 그것은 누군가에게 유용 할 것이고, 나는 동일한 문제를 가지고있다. 그리고 구글과 stem sitemesh 소스에 대한 연구 후에 ConfigDecoratorMapping을 확장함으로써 문제를 해결할 것이다. 여기 있습니다:
/** * Created by IntelliJ IDEA. * User: Inf-root * Date: 30.06.11 * Time: 1:00 * */ public class ConfigDecoratorMapperSpringMvcSupport extends ConfigDecoratorMapper { private static final Logger LOG = Logger.getLogger(ConfigDecoratorMapperSpringMvcSupport.class); private ConfigLoader configLoader = null; /** Create new ConfigLoader using '/WEB-INF/decorators.xml' file. */ public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException { LOG.debug("init()..."); super.init(config, properties, parent); try { String fileName = properties.getProperty("config", "/WEB-INF/decorators.xml"); configLoader = new ConfigLoader(fileName, config); } catch (Exception e) { throw new InstantiationException(e.toString()); } } /** Retrieve {@link com.opensymphony.module.sitemesh.Decorator} based on 'pattern' tag. */ public Decorator getDecorator(HttpServletRequest request, Page page) { LOG.debug("getDecorator()..."); String thisPath = request.getServletPath(); LOG.debug("\tThisPath: " + thisPath); String requestURI = request.getRequestURI(); LOG.debug("\t\tGet request URI: " + requestURI); //TODO check indexes thisPath = "/springURITemplate" + requestURI.substring(request.getContextPath().length(), requestURI.length() - 1); LOG.debug("\t\t\tThisPath: " + thisPath); String name = null; try { name = configLoader.getMappedName(thisPath); } catch (ServletException e) { e.printStackTrace(); } LOG.debug("\tResolved decorator name: " + name); Decorator result = getNamedDecorator(request, name); LOG.debug("Decorator is null ? " + (result == null)); return result == null ? super.getDecorator(request, page) : result; } }
내 decorators.xml에는 다음과 같은 내용이 포함되어 있습니다.
<?xml version="1.0" encoding="ISO-8859-1"?> <decorators defaultdir="/web/decorators"> <decorator name="admin_decorator" page="admin_decorator.jsp"> <pattern>/springURITemplate/a/administration*</pattern> </decorator> </decorators>
Spring 3.0.5와 함께 tomcat 7에서 테스트되었습니다.
-
==============================
4./ spring / cliente / index * 또는 / spring / cliente / index / *를 시도 했습니까?
/ spring / cliente / index * 또는 / spring / cliente / index / *를 시도 했습니까?
from https://stackoverflow.com/questions/2859014/sitemesh-and-spring-mvc-decorator-pattern-problems by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] 모든 jsp 페이지에 css 및 js 파일을 포함하십시오. (0) | 2019.04.02 |
---|---|
[SPRING] Spring JPA / Hibernate EmptyInterceptor가 Entitymanager / Spring beans를 주입하지 않음 (0) | 2019.04.02 |
[SPRING] Spring 부트에서 구성된 @Autowired 필터 사용 (0) | 2019.04.02 |
[SPRING] Android Spring 파일 업로드 OutofMemory (0) | 2019.04.02 |
[SPRING] [org.thymeleaf.templateresolver.ServletContextTemplateResolver]를 인스턴스화하지 못했습니다 : 기본 생성자가 없습니다 (0) | 2019.04.02 |