网站赏析案例,牡丹江林口县建设局网站,淮安市做网站,暴雪中国官网SiteMesh参考 作者#xff1a;kongxx (kongxxgmail.com)安装 首先从sitemesh下载安装包#xff0c;这里使用的是2.2.1版本。 创建一个Web应用程序#xff0c;这里我创建一个名为myapp的Web应用程序#xff1b; 复制sitemesh-2.2.1.jar文件到{myapp}/WEB-INF/lib目录下kongxx (kongxxgmail.com) 安装 首先从sitemesh下载安装包这里使用的是2.2.1版本。 创建一个Web应用程序这里我创建一个名为myapp的Web应用程序 复制sitemesh-2.2.1.jar文件到{myapp}/WEB-INF/lib目录下 编辑{myapp}/WEB-INF/web.xml文件 ?xml version1.0 encodingUTF-8? web-app xmlnshttp://java.sun.com/xml/ns/j2ee xmlns:xsihttp://www.w3.org/2001/XMLSchema-instance xsi:schemaLocationhttp://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd version2.4 filter filter-namesitemesh/filter-name filter-classcom.opensymphony.module.sitemesh.filter.PageFilter/filter-class /filter filter-mapping filter-namesitemesh/filter-name url-pattern/*/url-pattern /filter-mapping session-config session-timeout 30 /session-timeout /session-config welcome-file-list welcome-file index.jsp /welcome-file /welcome-file-list /web-app 添加蓝色高亮部分。 在{myapp}/WEB-INF/目录下创建decorators.xml文件并且输入一下内容 ?xml version1.0 encodingISO-8859-1? decorators defaultdir/decorators decorator namemain pagemain.jsp pattern/*/pattern /decorator decorator namepanel pagepanel.jsp/ decorator nameprintable pageprintable.jsp/ /decorators 安装完毕。 例子1 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator decorator namemydecorator1 pagemydecorator1.jsp pattern/test1.jsp/pattern /decorator 在{myapp}/decorators目录下添加mydecorator1.jsp文件内容如下: % taglib urihttp://www.opensymphony.com/sitemesh/decorator prefixdecorator % html head titleMy Site - decorator:title defaultWelcome! //title decorator:head / /head body decorator:body / pThis message is in /decorators/mydecorator1.jsp/p /body /html 在{myapp}目录下添加test1.jsp文件内容如下 %page contentTypetext/html% %page pageEncodingUTF-8% html head meta http-equivContent-Type contenttext/html; charsetUTF-8 titleThis is test1/title /head body bThis is test1/b /body /html 打开浏览器访问http://localhost:8080/myapp/test1.jsp将会出现一下内容 This is test1 This message is in /decorators/mydecorator1.jsp 例子2 (decorator:getProperty tag) 有时候我们期望修改页面中某个有固定标记的片段例如我们的jsp中有一个标记mytag.../mytag此时可以用如下方法实现 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator decorator namemydecorator2 pagemydecorator2.jsp pattern/test2.jsp/pattern /decorator 在{myapp}/decorators目录下添加mydecorator2.jsp文件内容如下: % taglib urihttp://www.opensymphony.com/sitemesh/decorator prefixdecorator % html head titleMy Site - decorator:title defaultWelcome! //title decorator:head / /head body decorator:body / decorator:getProperty propertypage.content1/ decorator:getProperty propertypage.content2/ !-- do nothing -- decorator:getProperty propertypage.content3/ pThis message is in /decorators/mydecorator2.jsp/p /body /html 在{myapp}目录下添加test2.jsp文件内容如下 %page contentTypetext/html% %page pageEncodingUTF-8% html head meta http-equivContent-Type contenttext/html; charsetUTF-8 titleThis is test2/title /head body bThis is test2/b bUse lt;decorator:getPropertygt; tag/b content tagcontent1pThis is content1/p/content content tagcontent2pThis is content2/p/content content tagcontent4pThis is content4, it shouldnt be display/p/content /body /html 打开浏览器访问http://localhost:8080/myapp/test2.jsp将会出现一下内容 This is test2 Use decorator:getProperty tag This is content1 This is content2 This message is in /decorators/mydecorator2.jsp 例子3 (page:applyDecorator tag) 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator decorator namemydecorator3 pagemydecorator3.jsp pattern/test3.jsp/pattern /decorator decorator namemydecorator31 pagemydecorator31.jsp /decorator 在{myapp}/decorators目录下添加mydecorator3.jsp文件内容如下: % taglib urihttp://www.opensymphony.com/sitemesh/decorator prefixdecorator % % taglib urihttp://www.opensymphony.com/sitemesh/page prefixpage % html head titleMy Site - decorator:title defaultWelcome! //title decorator:head / /head body decorator:body / page:applyDecorator namemydecorator31 content tagcontent1pThis is content1/p/content content tagcontent2pThis is content2/p/content /page:applyDecorator /body /html 在{myapp}/decorators目录下添加mydecorator31.jsp文件内容如下: % taglib urihttp://www.opensymphony.com/sitemesh/decorator prefixdecorator % % taglib urihttp://www.opensymphony.com/sitemesh/page prefixpage %pibegin/i/decorator:getProperty propertypage.content1/decorator:getProperty propertypage.content2/piend/i/ 在{myapp}目录下添加test3.jsp文件内容如下 %page contentTypetext/html% %page pageEncodingUTF-8% html head meta http-equivContent-Type contenttext/html; charsetUTF-8 titleThis is test3/title /head body bThis is test3/b bUse lt;page:applyDecoratorgt; tag/b /body /html 注意相对于例子2这里已经没有了content tagXXX/标签。 打开浏览器访问http://localhost:8080/myapp/test3.jsp将会出现一下内容 This is test3 Use page:applyDecorator tag begin This is content1 This is content2 end 这里我在mydecorator3.jsp中应用了mydecorator31.jsp的的decorator并且将原来在test2.jsp中的 content /标签复制到mydecorator3.jsp中此时对于content tagxxx/的标签将会由mydecorator31.jsp了装饰。 例子4 (page:param tag) 在{myapp}/WEB-INF/decorators.xml文件中添加以下decorator decorator namemydecorator4 pagemydecorator4.jsp pattern/test4.jsp/pattern /decorator decorator namemydecorator41 pagemydecorator41.jsp /decorator 在{myapp}/decorators目录下添加mydecorator4.jsp文件内容如下: % taglib urihttp://www.opensymphony.com/sitemesh/decorator prefixdecorator % % taglib urihttp://www.opensymphony.com/sitemesh/page prefixpage % html head titleMy Site - decorator:title defaultWelcome! //title decorator:head / /head body decorator:body / page:applyDecorator namemydecorator41 content tagcontent1pThis is content1/p/content content tagcontent2pThis is content2/p/content page:param namepage.content1pThis content1 has been replaced/p/page:param /page:applyDecorator /body /html 在{myapp}/decorators目录下添加mydecorator41.jsp文件内容如下: % taglib urihttp://www.opensymphony.com/sitemesh/decorator prefixdecorator % % taglib urihttp://www.opensymphony.com/sitemesh/page prefixpage %pibegin/i/decorator:getProperty propertypage.content1/decorator:getProperty propertypage.content2/piend/i/ 在{myapp}目录下添加test4.jsp文件内容如下 %page contentTypetext/html% %page pageEncodingUTF-8% html head meta http-equivContent-Type contenttext/html; charsetUTF-8 titleThis is test4/title /head body bThis is test4/b bUse lt;page:paramgt; tag/b /body /html 打开浏览器访问http://localhost:8080/myapp/test4.jsp将会出现一下内容 This is test4 Use page:param tag begin This content1 has been replaced This is content2 end 这里我在mydecorator4.jsp中应用了mydecorator41.jsp的的decorator并且添加了page:param namepage.content1标签那么此时页面上将会用page:param标签中的内容替换原来在decorator:getProperty propertypage.content1/中的内容因此页面将不在“This is content1”而显示“This content1 has been replaced”。 转载于:https://www.cnblogs.com/wdpp/archive/2007/05/13/2386403.html