Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 482 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
<jsp:include> doesn't work in magnolia cms

#1
I have a project in which I integrate Magnolia cms with Spring mvc. The spring servlet is loaded as a module in magnolia and is assigned the pattern `/web/*`. The servlet is defined in the module descriptor so there is no servlet definition in the web.xml file, there is only the magnolia filter chain defined there.

The problem I'm having is that when I try the following code

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

for example in a magnolia page template, I get an error where it says it cannot find the file and it searches for it in `/src/main/webapp/web/header`.

But if I declare the spring servlet in web.xml there is no error and it works.

Can someone please tell me why is this happening? Why can't `<jsp:include>` just look through the magnolia filter chain and find that the spring servlet maps that request and give back the requested page?

Thanks :)

This is my web.xml file:

<?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

[To see links please register here]

;

<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>

This is how I define the spring servlet inside the module descriptor for blossom:

<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>

This is the main template that I used for the page home in magnolia:

<%@ 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>

The page header.jsp is under `webapps/WEB-INF/views/`.

The error it shows me in eclipse next to the include is:

> Fragment "/web/header" was not found at expected path
> /project_name/src/main/webapp/web/header

The error that it comes up in the browser is:

> HTTP Status 404 - /project_name/web/header

The thing is that if I put the following code in web.xml it works:

<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>

I hope this helps.. Thank you very much :)
Reply

#2
Most of the filters in the Magnolia filter chain doesn't handle includes by default. In your case of course it makes sense to have the servlet accept includes. You can enable this by changing the dispatch rules on the servlet in /server/filters/servlets/[your servlet].

Copy /server/filters/dispatching to /server/filters/servlets/[your servlet] and set dispatching/include/toMagnoliaResource to true.

Magnolia classifies requests as either targeting magnolia resources or web container resources and the filter handles them differently. The configuration for how they're classified is in /server/webContainerResources, everything not matched by the rules there is a magnolia resources.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through