English 中文(简体)
Getting sitemesh to work with struts2
原标题:

I m trying to integrate sitemesh into my struts2 app, but i m finding that it s not making any difference and isn t showing any errors (or anything sitemesh related at all) in the logs.

I ve started by following all the documentation on the sitemesh site, had no luck, so now i m trying to copy what s been done in the sitemesh-example download, to no avail. Any ideas would be great.

web-inf/web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
  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">
  <display-name>Sample</display-name>

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

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


  <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>
  </filter-mapping>

</web-app>

web-inf/decorators.xml:

<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/decorators">
    <decorator name="main" page="main.jsp">
          <pattern>*</pattern>
    </decorator>
</decorators> 

web-inf/lib folder:

sitemesh-2.4.2.jar
sitemesh-decorator.tld
sitemesh-page.tld

decorators/main.jsp:

<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="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">
 <title>
 My Site - <decorator:title default="Welcome!" />
 </title>
 <decorator:head />
</head>

 <body>
 <h1><decorator:title default="Welcome!" /></h1>
 <p><decorator:body /></p> 
 <p><small>
 (<a 
    href="?printable=true">printable version</a>)
    </small></p>
 </body>
</html>

Thanks guys

最佳回答

The only thing I am seeing is here:

 <?xml version="1.0" encoding="UTF-8"?>
 <decorators defaultdir="/decorators">
  <decorator name="main" page="main.jsp">
      <pattern>/*</pattern>
  </decorator>
 </decorators>

You need a /* not just a * as the pattern.

Maybe check the location of the decorators directory. Is it in the root of the app?

I also have this in my setup, I don t know if it makes a difference or not.

  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签