`
Luob.
  • 浏览: 1573258 次
  • 来自: 上海
社区版块
存档分类
最新评论

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
分享到:
评论

相关推荐

    sitemesh简单教程页面装配器

    sitemesh 应用 Decorator 模式,用 filter 截取 request 和 response,把页面组件 d,content,banner 结合为一个完整的视图。通常我们都是用 include 标签在每个 jsp 页面中来 断的包含各种header , ...

    sitemesh 完美合集 4个资料和jar文件

    sitemesh应用Decorator模式,用filter截取request和response,把页面组件head,content,banner结合为一个完整的视图。通常我们都是用include标签在每个jsp页面中来不断的包含各种header, stylesheet, scripts and ...

    sitemesh

    SiteMesh是一个Web页面布局修饰框架, 用于构建包含大量页面, 需要一致的外观样式(look/fell), 导航和布局机制的大型网站. SiteMesh应用Decorator模式,用filter截取request和response,把页面组件head,content,...

    siteMesh例子

    SiteMesh应用Decorator模式,用filter截取request和response,把页面组件head,content,banner结合为一个完整的视图。通常我们都是用include标签在每个jsp页面中来不断的包含各种header, stylesheet, scripts and ...

    sitemesh-examples-hellowebapp

    这是一个非常简单的“ hello world” Web应用程序。 它演示了将页面装饰器应用于网站的内容。 它使用下载SiteMesh jar,并使用 WebServer运行示例。 本质上,它是Gradle可以立即运行的教程。 如果您的系统上未 ,...

    jsoup jar包

    复合页面,始终是一个开发web应用时必须面对的问题,对struts的titles有厌倦,听说sitemesh不错,尝试,原以为复杂,谁知用起来是那么地简单,太令人惊叹! 写下试用教程: 1.准备一个web项目,到sitemesh官方网站...

    Java后端知识图谱帮助Java初学者成长.rar

    本文首先会给出关于 java后台开发 和 前端适配 的一些建议学习路线,接着简单解释一些应用到的高频技术,帮助大家理解和学习,算是一个入门篇。 2.Java后台开发知识一览 1、后端 WEB服务器:Weblogic、Tomcat、...

    Grails 中文参考手册

    6.2.4 使用Sitemesh布局 6.3 标签库 6.3.1 简单标签 6.3.2 逻辑标签 6.3.3 迭代标签 6.3.4 标签命名空间 6.4 URL映射 6.4.1 映射到控制器和操作 6.4.2 嵌入式变量 6.4.3 映射到视图 6.4.4 映射到响应代码 6.4.5 映射...

    Struts2 in action中文版

    12.2.1 SiteMesh 266 12.2.2 Tiles 267 12.2.3 JFreeChart 269 12.3 内部组件系统 271 12.3.1 Bean 271 12.3.2 常量 272 12.3.3 注入 272 12.3.4 Struts内部扩展点 273 12.4 编写浏览路径插件 274 12.5 小结 278 第...

    java开发常用jar包

    Sitemesh 是一个基于WEB页面的布局、装饰以及应用整合的开源框架。它能帮助我们在由大量页面构成的项目中创建一致的页面布局和外观,如一致的导航条,一致的 banner,一致的版权,等等。它不仅仅能处理动态的内容,...

Global site tag (gtag.js) - Google Analytics