sitemesh 配置

1.maven 配置

<dependency>
    <groupId>opensymphony</groupId>
    <artifactId>sitemesh</artifactId>
    <version>2.4.2</version>
</dependency>


2.web.xml 配置

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

3.添加decorators.xml

    添加路径为:WEB-INF/目录下

<?xml version="1.0" encoding="UTF-8"?>
<decorators>
    <decorator name="default-theme" page="/default-theme.jsp">
        //要渲染的url的请求地址
        <pattern>/home/*</pattern>
    </decorator>
</decorators>

4.添加默认样式文件

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
 <!-- 添加上taglib 库 -->
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator" prefix="decorator" %>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/page" prefix="page" %>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>
         <!-- 如果被渲染的页面中添加了title 就用,没有就用 default 中配置的  -->
        <decorator:title  default="ls"  />
    <title>
    <%@ include file="/common/head.jsp"%>
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
        <!-- Main content -->
	    <section class="content">
	         <!-- 被渲染的页面,显示的地方 -->
	     	<decorator:body></decorator:body>
	    </section>
        <!-- /.Left col -->
  </body>
</html>

5.添加要渲染的文件

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <!-- 在要渲染的页面中添加  title 为加载到  样式页面上去 -->
    <title>我的渲染页面</title> 
  </head>
  <body class="hold-transition skin-blue sidebar-mini">
      hello world!
  </body>
</html>

6.测试连接地址就可以了。

转载于:https://my.oschina.net/lavedream/blog/510546

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值