s:在装饰者sitemesh上没有替换url

时间:2013-05-29 10:28:39

标签: struts2 taglib sitemesh

:当使用带有sitemesh的装饰器时,url标签不会被替换为html代码。在下一个例子中将正确解释。

的web.xml:

[...]
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            WEB-INF/security-context.xml
            WEB-INF/applicationContext.xml
        </param-value>
    </context-param>

<filter>
  <filter-name>sitemesh</filter-name>
  <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>

<filter>
  <filter-name>springSecurityFilterChain</filter-name>
  <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter>
    <filter-name>struts-cleanup</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>

<filter-mapping>
  <filter-name>sitemesh</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener>

<welcome-file-list>
    <welcome-file>login.jsp</welcome-file>
</welcome-file-list>
[...]
</web-app>

的Login.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-15" pageEncoding="ISO-8859-15"%>
<%@ taglib prefix="s" uri="/struts-tags" %> 
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

**<link rel="stylesheet" type="text/css" href="<s:url value="/style/global.css" />" />**
[...]

Layout.jsp :(我的sitemesh装饰器)

<%@ page language="java" contentType="text/html; charset=ISO-8859-15" pageEncoding="ISO-8859-15"%>
<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<%@ taglib prefix="page" uri="http://www.opensymphony.com/sitemesh/page" %>
<%@taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15">

        **<link rel="stylesheet" type="text/css" href="<s:url value="/style/global.css" />" />**

    </head>
[...]

结果HTML:

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Café Mirabeau</title>
    **<link rel="stylesheet" type="text/css" href="<s:url value='/style/global.css' />"** />
</head>
<body>
    <h1>Header</h1>
    <p><b>Navigation</b></p>    
    <hr />




**<link rel="stylesheet" type="text/css" href="/(myapp)/style/global.css" />**

正如您所看到的,login.jsp和layout.jsp上的行相同,但只有在login.jsp上才能正确替换。

任何人都知道会发生什么?

1 个答案:

答案 0 :(得分:1)

尝试使用struts2过滤器:

<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
在sitemesh过滤器之前

<filter-mapping>
  <filter-name>sitemesh</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

web.xml

相关问题