繁体   English   中英

<jsp:include>在木兰cms中不起作用

[英]<jsp:include> doesn't work in magnolia cms

我有一个将Magnolia cms与Spring mvc集成的项目。 spring servlet作为木兰中的模块加载,并被分配为/web/*模式。 该servlet是在模块描述符中定义的,因此web.xml文件中没有servlet定义,仅在其中定义了木兰过滤器链。

我遇到的问题是,当我尝试以下代码时

<jsp:include path="/web/header" />

例如在木兰页面模板中,出现错误,提示它找不到文件,并在/src/main/webapp/web/header搜索该文件。

但是,如果我在web.xml中声明spring servlet,则没有错误,并且可以正常工作。

有人可以告诉我为什么会这样吗? 为什么<jsp:include>只浏览木兰过滤器链,发现spring servlet映射了该请求并返回了所请求的页面?

谢谢 :)

这是我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <filter>
        <display-name>Magnolia global filters</display-name>
        <filter-name>magnoliaFilterChain</filter-name>
        <filter-class>info.magnolia.cms.filters.MgnlMainFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>magnoliaFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>

    <context-param>
        <param-name>magnolia.initialization.file</param-name>
        <param-value>
          WEB-INF/config/${servername}/${webapp}/magnolia.properties, WEB-INF/config/${servername}/magnolia.properties,
          WEB-INF/config/${webapp}/magnolia.properties, WEB-INF/config/default/magnolia.properties,
          WEB-INF/config/magnolia.properties
        </param-value>
    </context-param>

    <listener>
        <listener-class>info.magnolia.module.blossom.support.ServletContextExposingContextListener</listener-class>
    </listener>
    <listener>
        <listener-class>info.magnolia.cms.servlets.MgnlServletContextListener</listener-class>
    </listener>

</web-app>

这就是我如何在模块描述符中定义spring servlet以便进行开花:

    <servlets>
        <servlet>
            <name>Spring Servlet</name>
            <class>info.magnolia.module.blossom.web.InstallationAwareDispatcherServlet</class>
            <comment>Used for spring as dispatcher servlet</comment>
            <mappings>
                <mapping>/web/*</mapping>
            </mappings>
            <params>
                <param>
                    <name>contextConfigLocation</name>
                    <value>/WEB-INF/spring/appServlet/servlet-context.xml</value>
                </param>
            </params>
        </servlet>
    </servlets>

这是我用于木兰首页的主要模板:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!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=UTF-8">
                <title>${content.title}</title>
    </head>

    <body>

        <jsp:include page="/web/header" />

    </body>
</html>

header.jsp页面位于webapps/WEB-INF/views/

在eclipse中包含项旁边显示给我的错误是:

在预期路径/ project_name / src / main / webapp / web / header上找不到片段“ / web / header”

浏览器中出现的错误是:

HTTP状态404-/ project_name / web / header

关键是,如果我将以下代码放入web.xml中,它将起作用:

    <servlet>
        <servlet-name>Spring Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Spring Servlet</servlet-name>
        <url-pattern>/web/*</url-pattern>
    </servlet-mapping>

希望对您有所帮助。非常感谢:)

默认情况下,Magnolia过滤器链中的大多数过滤器都不处理包含。 当然,在您的情况下,让Servlet接受包含是有意义的。 您可以通过更改/ server / filters / servlets / [您的servlet]中servlet上的调度规则来启用此功能。

将/ server / filters / dispatching复制到/ server / filters / servlets / [您的servlet],并将dispatch / include / toMagnoliaResource设置为true。

木兰将请求分类为针对木兰资源或Web容器资源,并且过滤器以不同的方式处理它们。 它们的分类方式配置在/ server / webContainerResources中,所有与规则不匹配的内容都有木兰资源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM