sitemesh框架使用入门

sitemesh框架使用入门


上篇博客写到如何创建maven web项目。大家是不是有点迷茫,创建maven项目能干嘛?那么,我就结合maven 项目简单使用和sitemesh框架使用入门一起讲。

我们先了解什么是sitemesh?

Sitemesh是由一个基于Web页面布局、装饰及与现存Web应用整合的框架。是基于Servlet的filter的,即过滤流。它是通过截取response,并进行装饰后再交付给客户。需要两类页面,第一是模版页面,一个是被模版修饰的页面。

开始码砖了。。。。

第一步:创建maven web项目,不清楚的可以根据 eclipse 创建maven web项目 具体了解

第二步:导包

<dependency>
    <groupId>opensymphony</groupId>
    <artifactId>sitemesh</artifactId>
    <version>2.4.2</version>
</dependency> 
第三步: 在web.xml文件中配置filter

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

第四步:在WEB-INF/下创建decorators.xml描述装饰器

<?xml version="1.0" encoding="utf-8"?>
<decorators defaultdir="/WEB-INF/layouts/">
    <decorator name="default" page="default.jsp">
        <pattern>/*</pattern>
    </decorator>
</decorators> 

第五步:创建模版页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><sitemesh:title default="装饰器页面..." /></title>
<sitemesh:head />
</head>
<body>
	<p>=============头部菜单=============</p>
	<hr>
	<sitemesh:body />
	<hr>
	<p>//底部信息\\\\\\\\\\\\\\\\\\\\\\\\\\\\</p>
</body>
</html>
第六步:创建被模版修饰的页面,first.jsp和second.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>被修饰的第一个页面</title>
</head>
<body>
	<p>这是第一个页面</p>
	<a href="views/second.jsp">下一页</a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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=UTF-8">
<title> 被修饰的第二个页面</title>
</head>
<body>
	<p>这是第二个页面</p>
</body>
</html>
第七步:右击项目====run as====maven test,执行maven项目,执行maven测试,同时自动现在依赖的jar。maven clean 清楚上次构建的文件,maven install 把项目安装到本地库,让其他项目依赖。

第八步:在浏览器上访问,效果图如下:



资源下载地址:http://download.csdn.net/detail/qq_19558705/9277105

每天在进步,每天在成长,如有问题和建议可以留言,我会及时修正。


更多干货等你来拿 http://www.itit123.cn/











  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值