Sitemesh3 + Freemarker, only body not rendering - struts2

I have tried alot but no success. Only body is not rendering. All the includes are merged properly in decorator. See Result Page.
Specs
jdk = 1.7
struts2 = 2.3.4.1
sitemesh = 3.0-alpha-2
Result Page
<!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-1">
<link rel="stylesheet" href="/css/bootstrap.min.css" />
</head>
<body id="public">
<div class="container">
No Body
</div>
</body>
</html>
sitemesh3.xml
<sitemesh>
<mapping decorator="/WEB-INF/decorators/main.ftl"/>
</sitemesh>
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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_3_0.xsd">
<display-name>Struts2 SiteMesh Freemarker Web Application</display-name>
<listener>
<listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>
</listener>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class>
</filter>
<filter>
<filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>struts-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-prepare</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>struts-execute</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>sitemesh-freemarker</servlet-name>
<servlet-class>com.opensymphony.module.sitemesh.freemarker.FreemarkerDecoratorServlet</servlet-class>
<init-param>
<param-name>TemplatePath</param-name>
<param-value>/</param-value>
</init-param>
<init-param>
<param-name>default_encoding</param-name>
<param-value>ISO-8859-1</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>sitemesh-freemarker</servlet-name>
<url-pattern>*.ftl</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.ftl</welcome-file>
</welcome-file-list>
</web-app>
POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myapp</groupId>
<artifactId>Struts2_SiteMesh3_FreeMarker</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>Struts2_SiteMesh3_FreeMarker WebApp</name>
<url>http://maven.apache.org</url>
<properties>
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<struts2.version>2.3.4.1</struts2.version>
<slf4j.version>1.6.6</slf4j.version>
<sitemesh.version>3.0-alpha-2</sitemesh.version>
</properties>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<!--Start Slf4j-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!--End Slf4j-->
<!-- Start struts2 dependencies -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
</dependency>
<!-- End struts2 dependencies -->
<!-- Start SiteMesh dependencies -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-sitemesh-plugin</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.sitemesh</groupId>
<artifactId>sitemesh</artifactId>
<version>${sitemesh.version}</version>
</dependency>
<!-- End SiteMesh dependencies -->
</dependencies>
<build>
<finalName>Struts2_SiteMesh3_FreeMarker</finalName>
</build>
</project>
decorator
<!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-1">
<#include "../include/meta.ftl">
</head>
<body id="public">
<#include "../include/navigation.ftl">
<div class="container">
<#include "../include/search.ftl">
${body}
</div>
</body>
</html>
index.ftl
<html>
<head>
<title>Hello World</title>
<meta name='description' content='A simple page'>
</head>
<body>
<p>Hello <strong>world</strong>!</p>
</body>
</html>
Project Structure

add servlet freemarker.ext.servlet.FreemarkerServlet to web xml at <url-pattern>*.ftl</url-pattern> and use <sitemesh:write property='body'/> instead of ${body} in your decorator.ftl

Related

Integrating Struts2 Sitemesh DWR

I'm attempting to integrate Struts2 ver 2.5.2, DWR ver 2.0,5, and Sitemesh ver 2.5. My DWR is (almost) already work fine. I can open [CONTEXT]/dwr/engine.js and util.js, and also [CONTEXT]/dwr/interface/Arithmetic.js.
The problem is, when I open index.jsp which contains dwr call, the dwr js variable is not defined as well the Arithmetic variable.
The index.jsp itself already decorated from the Sitemesh filter.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com /xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value> true </param-value>
</init-param>
<init-param>
<param-name>crossDomainSessionSecurity</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<!-- Filters -->
<filter>
<filter-name>struts-prepare</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class>
</filter>
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>
<filter>
<filter-name>struts-execute</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-prepare</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts-execute</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>jspSupportServlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>5</load-on-startup>
</servlet>
<listener>
<listener- class>org.apache.struts2.dispatcher.listener.StrutsListener</listener-class>
</listener>
</web-app>
decorators.xml
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/decorators">
<excludes>
<pattern>/dwr/*</pattern>
</excludes>
<decorator name="basic-theme" page="basic-theme.jsp">
<pattern>/*</pattern>
</decorator>
</decorators>
dwr.xml
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN"
"http://directwebremoting.org/schema/dwr20.dtd">
<dwr>
<allow>
<create creator="new" javascript="HelloAjaxService">
<param name="class" value="com.test.struts.ajax.HelloAjaxService" />
</create>
</allow>
</dwr>
index.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# 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>
<title>Hello World</title>
<script type="text/javascript" src="/strutsSitemesh/dwr/engine.js"></script>
<script type='text/javascript' src='/strutsSitemesh/dwr/util.js'></script>
<script type='text/javascript' src='/strutsSitemesh/dwr/interface /HelloAjaxService.js'></script>
</head>
<body>
<div
style="background-color: #ffeaa7; font-weight: bold; width: 300px;"
id="divResponse">
<s:form action="hello" method="post">
<s:textfield id="name" name="name" label="Name" size="20"
onkeypress="sayHello()" />
<s:textfield name="age" label="Age" size="20" />
<s:submit name="submit" label="Submit" align="center" />
</s:form>
<script type="text/javascript">
function sayHello() {
console.log(dwr.util.getValue("name"));
HelloAjaxService.sayHelloAjax(function(data) {
dwr.util.setValue("divResponse", data);
});
}
</script>
</body>
</html>
If I commented filter-mapping sitemesh ---- the DWR call will work just fine. So I assume, the request will filtered by SitemeshFilter, and strangely it will not go to DWR filter. I tried to search about how to arrange filter in sequence, but nothing comes up. Any help appreciated. Big thanks.
So, I solved it by moving dwr js declaration to the body tag of index.jsp. It happened because in my decorators.jsp, I only put <decorator:body>, and because of that, the <head> tag in decorators.jsp take precedence of the actual .jsp file(In this case, index.jsp).

Can't login with spring security

I created a simple project to login using spring security.
The composition of my project is presented by screenshot:
.
bellow are the required files:
spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">
<http auto-config="true">
<intercept-url pattern="/welcome.jsf" access="ROLE_USER" />
<form-login login-page="/login.jsf" default-target-url="/welcome.jsf"
authentication-failure-url="/login.jsf?status=error" />
<logout logout-success-url="/login.jsf?status=logout" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="walid" password="111" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web_1:web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd
http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd
http://xmlns.jcp.org/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="Spring-Security-Custom-Login-Form_ID"
version="2.4">
<javaee:display-name>HelloWorld</javaee:display-name>
<javaee:listener>
<javaee:listener-class>org.springframework.web.context.ContextLoaderListener</javaee:listener-class>
</javaee:listener>
<javaee:filter>
<javaee:filter-name>springSecurityFilterChain</javaee:filter-name>
<javaee:filter-class>org.springframework.web.filter.DelegatingFilterProxy</javaee:filter-class>
</javaee:filter>
<javaee:filter-mapping>
<javaee:filter-name>springSecurityFilterChain</javaee:filter-name>
<javaee:url-pattern>/*</javaee:url-pattern>
</javaee:filter-mapping>
<javaee:context-param>
<javaee:param-name>contextConfigLocation</javaee:param-name>
<javaee:param-value>/WEB-INF/spring-security.xml</javaee:param-value>
</javaee:context-param>
<javaee:context-param>
<javaee:description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</javaee:description>
<javaee:param-name>javax.faces.STATE_SAVING_METHOD</javaee:param-name>
<javaee:param-value>client</javaee:param-value>
</javaee:context-param>
<javaee:context-param>
<javaee:param-name>javax.servlet.jsp.jstl.fmt.localizationContext</javaee:param-name>
<javaee:param-value>resources.application</javaee:param-value>
</javaee:context-param>
<javaee:listener>
<javaee:listener-class>com.sun.faces.config.ConfigureListener</javaee:listener-class>
</javaee:listener>
<javaee:servlet>
<javaee:servlet-name>Faces Servlet</javaee:servlet-name>
<javaee:servlet-class>javax.faces.webapp.FacesServlet</javaee:servlet-class>
<javaee:load-on-startup>1</javaee:load-on-startup>
</javaee:servlet>
<javaee:servlet-mapping>
<javaee:servlet-name>Faces Servlet</javaee:servlet-name>
<javaee:url-pattern>/faces/*</javaee:url-pattern>
</javaee:servlet-mapping>
</web_1:web-app>
login.xhtml
<?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"
xmlns:c="http://java.sun.com/jstl/core">
<body>
<h3>Enter your username and password</h3>
<form method="post" action="j_spring_security_check">
UserName :<input name="j_username" type="text" /> <br />
Password :<input name="j_password" type="password" /> <br />
<input value="Login" type="submit" />
</form>
<br />
<c:if test="${param.status=='error'}">
<label style="color:red">Invalid username or password!!</label>
</c:if>
<c:if test="${param.status=='logout'}">
<label style="color:red">Logged out successfully!</label>
</c:if>
</body>
</html>
welcome.xhtml
<?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">
<body>
<h2>Welcome Page</h2>
<br />
Logout
</body>
</html>
After login with (walid,111), I got this exception
Could you please help me solving this. Thanks a lot.
your web.xml seems wrong, you can try this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="Spring-Security-Database-Authentication_ID" version="2.4">
<display-name>Spring-Security-Database-Authentication</display-name>
<servlet>
<servlet-name>JSF Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JSF Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>JSF Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-security.xml</param-value>
</context-param>
</web-app>
HTH

JSF error web page not found

Hello Every body i'm a beginner in j2ee developping .. i developed a jsf application , created some jsf views within , but when i try to execute it on my tomcat 7 server , all i see is a "page web introuvable" message
here is my code:
login.xhtml:
<!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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
<title>Authentification</title>
</h:head>
<h:body>
<h:form>
<h:panelGrid columns="2">
<h:outputLabel value="Login:" />
<h:inputText value="#{loginBean.login}" size="30"/>
<h:outputLabel value="Mot de passe:" />
<h:inputSecret id="pwdId" value="#{loginBean.password}" size="30" />
<h:commandButton value="Valider" type="submit" action="#{loginBean.authentification}" />
<h:commandButton type="reset" value="Reset" />
</h:panelGrid>
</h:form>
<h:messages style="COLOR: #ff0000;"/>
</h:body>
</html>
index.jsp:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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-1">
<title>Insert title here</title>
</head>
<body>
<% response.sendRedirect("pages/login.jsf"); %>
</body>
</html>
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>GestionBibliotheque</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
</web-app>
JSP is not supported in JSF 2.
Create index.html with redirect to login page using meta tag:
<meta http-equiv="refresh" content="0; url=./login.jsf" />
Simple example here

s:url not replaced on decorator sitemesh

s:url tags are not being replaced to html code when using a decorator with sitemesh. In the next example will be correctly explained.
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: (my sitemesh decorator)
<%# 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>
[...]
The result 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" />**
As you can see, the same line is on the login.jsp and on layout.jsp, but only on login.jsp is correctly replaced.
Anyone knows what can be happening?
Try putting your struts2 filter:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
before the sitemesh filter
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
in your web.xml.

Struts2 and Jersey in single web application produces http 500 error

It shows http 500 with jasper error, while launching the application, Im using jersey and struts2 in same project. Any particular configuration is required. Eventhough, all jar files are included, it shows error.
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>RestExample</display-name>
<welcome-file-list>
<welcome-file>/jsp/login.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.src.matchmaker.services</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
</web-app>
struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.action.excludePattern" value="/rest/.*" />
<!-- Configuration for the default package. -->
<package name="default" extends="struts-default">
</package>
</struts>
login.jsp
<%--
Document : register
Created on : Jan 31, 2013, 11:18:43 AM
Author : wifin
![enter image description here][1]--%>
<%#page language="java" contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/match_login_style.css" type="text/css">
<link rel="icon" type="image/jpg" href="<%=request.getContextPath()%>/images/logo.jpg"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery.validation.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/login_validation.js"></script>
</head>
<body>
<div class="wrap">
<div class="back" align="center">
<form id="login" name="login" action="login.action" method="post">
<div align="center" class="header">Login</div>
<div id="err"><s:actionerror/></div>
<div class="tit">
Email Id: <input type="text" name="emailId" id="emailId"/>
<div class="clr"></div>
</div>
<div class="tit">
Password: <input type="password" name="password" id="password"/>
<div class="clr"></div>
</div>
<div>
<input class="btn" type="submit" name="reg" value="Login" id="reg" />
<input class="btn" type="reset" value="Cancel" id="cancel" />
</div>
</form>
<div><a class="link" href="<%=request.getContextPath()%>/jsp/register.jsp">New User?</a></div>
</div>
</div>
</body>
</html>
You page is being displayed without going through Struts2 filter. You need to call Struts2 action which will display your page as a result.
Also the org.apache.struts2.dispatcher.FilterDispatcher is deprecated since Struts 2.1.3, so if you are using version greater then 2.1.3 change FilterDispatcher to org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.
Also why not to intercept all url patterns with this filter? Change this filter <url-pattern> to <url-pattern>/*</url-pattern>.
BTW using scriptlets in JSP is a bad practice, use Struts2 tags instead.

Resources