让 sitemesh 与 struts2 一起工作

发布于 2024-08-12 04:58:49 字数 2450 浏览 2 评论 0原文

我正在尝试将 sitemesh 集成到我的 struts2 应用程序中,但我发现它没有任何区别,并且在日志中没有显示任何错误(或任何与 sitemesh 相关的内容)。

我开始遵循 sitemesh 网站上的所有文档,但没有运气,所以现在我尝试复制 sitemesh-example 下载中所做的内容,但无济于事。任何想法都会很棒。

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 文件夹:

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>

谢谢大家

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你的占有欲 2024-08-19 04:58:49

我唯一看到的是:

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

您需要 /* 而不仅仅是 * 作为模式。

也许检查装饰器目录的位置。它在应用程序的根目录中吗?

我的设置里也有这个,不知道有没有影响。

  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文