2

私は春に働く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の春サーブレットのマッピングを次のように変更します

SpringMVCディスパッチャーサーブレット*.htm

次のような新しいパターンを定義します。

<decorator page="application/themeManager/theme.jsp" name="dos">
    <pattern>/cliente/index.htm</pattern>
</decorator>

そしてそれは機能するので、これを春サーブレットのこのマッピングで機能させる方法はありますか?

<servlet-mapping>
    <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
    <url-pattern>/spring/*</url-pattern>
</servlet-mapping>
4

4 に答える 4

4

問題は、SiteMeshがRequest.getServletPath()を使用していることです。これは、SpringMVCアプリケーションですべてに対して「/spring」を返します。これは、com.opensymphony.module.sitemesh.DecoratorMapperインターフェイスを実装し、通常のConfigDecoratorMapperの代わりに使用することで見つかりました。次に、デコレータをリクエストにマッピングするために使用されるさまざまな引数を調べることができました。残念ながら、これでは、DispatcherServeletマッピングまたはそのバリアントで*.htmlサフィックスを使用するしか選択肢がないと思います。

もう1つのオプションは、PageDecoratorMapperを構成し、元の装飾されていないページでこのタグを使用して、使用するレイアウトを指定することです。

 <meta name="decorator" content="layoutName" /> 

ただし、URLマッピングの利点は無効になります。

于 2010-10-29T14:46:22.410 に答える
2

私はその正確な問題を抱えています。何が起こっているのかというと、web.xmlで指定したURLパスのすべての部分が、Springに渡される前に、Webサーバーによって削除されます。ただし、最後にワイルドカードを配置した場合に限ります。URLがwww.myapp.com/spring/cliente/index.htmlの場合、これを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にも当てはまります。Webサーバーが通過するものだけを確認します。

于 2010-06-21T21:44:29.643 に答える
2

多分それは誰かのために役立つでしょう、私は同じ問題を抱えています、そしてグーグルとstadingサイトメッシュソースで研究した後、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>

Spring3.0.5を使用してTomcat7でテスト済み

于 2011-06-29T18:50:43.890 に答える
0

/ spring / cliente /index*または/spring/ cliente / index / *を実行してみましたか?

于 2010-05-21T11:09:53.220 に答える