SiteMesh简单应用

1.在javaweb中加入 sitemesh-2.4.2.jar
2.在webroot下建立decorators 文件夹
3.建立 装饰器文件
leftRight.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<%@ taglib prefix="page" uri="http://www.opensymphony.com/sitemesh/page" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title><decorator:title default="装饰器页面"/></title>
<decorator:head/>
</head>

<body>
<div>
<ul style="list-style: none">
<li style="float: left;width:100px;height:180px;border-right:solid 1px gray;padding-left:10px;text-align:left;">
<font style="font-weogjt:bold;">歌曲列表</font>
<br/><br/>
<a href="text.jsp">浪子心声</a><br/>
<a href="#">如果有一天</a><br/>
<a href="#">跟我两辈子</a><br/>
<a href="#">流浪</a><br/>
<a href="#">天意</a><br/>
<a href="#">爱火烧不尽</a><br/>
<a href="#">兄弟</a><br/>
<a href="#">暗里着迷</a><br/>
<a href="#">来生缘</a><br/>
</li>
<li>
<decorator:body/>
</li>
</ul>
</div>
</body>
</html>




topbottom.jsp


<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="decorator" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<%@ taglib prefix="page" uri="http://www.opensymphony.com/sitemesh/page" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title><decorator:title default="装饰器页面"/></title>
<decorator:head/>
</head>

<body>
<center>
<div>
<page:applyDecorator page="/test.jsp" name="leftRight"/>
</div>
<hr/>
<div>
<decorator:body/>
</div>
</center>
</body>
</html>




test.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>使用SiteMesh框架</title>
</head>

<body>
<center>
<div>
<span style="color:green;font-weight:bold;">
浪子心声<br/>
刘德华<br/>
难分真与假人面多险诈<br/>
几许有共享荣华檐畔水滴不分差<br/>
难分真与假人面多险诈<br/>
几许有共享荣华檐畔水滴不分差<br/>
难分真与假人面多险诈<br/>
几许有共享荣华檐畔水滴不分差<br/>
难分真与假人面多险诈<br/>
几许有共享荣华檐畔水滴不分差<br/>
难分真与假人面多险诈<br/>
几许有共享荣华檐畔水滴不分差<br/>
难分真与假人面多险诈<br/>
几许有共享荣华檐畔水滴不分差<br/>
</span>
</div>
</center>
</body>
</html>



moreSongs.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>SiteMesh框架</title>

</head>

<body>
<center>
<div>
<a href="#">
更多歌曲点击这里<br/>
中国最大的音乐网站
</a>
</div>
</center>
</body>
</html>



5.在web-inf 下建立 decorators.xml 配置装饰器文件的修饰的请求

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


6.在web.xml中加入sitemesh的框架拦截器

<?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
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


7.访问 http://localhost:8080/SiteMesh/moreSongs.jsp
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值