创建JSP布局模板的最佳方法是什么?

编程入门 行业动态 更新时间:2024-10-23 07:40:35
本文介绍了创建JSP布局模板的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复: JSP技巧使模板更容易?

I我是JSPs和Servlets的新手,我想知道是否有一种简洁的方法来创建一个布局jsp并在类似的jsp页面上重用它,比如asp母版页。

I'm new to JSPs and Servlets, I'm wondering is there a neat way to create a layout jsp and reuse it on similar jsp pages, something like asp master pages.

我用Google搜索,有人说使用模板 http:// java.sun/developer/technicalArticles/javaserverpages/jsp_templates 使用jstl标记库。它说要放置这样的标签:

I googled it, some people say use templates java.sun/developer/technicalArticles/javaserverpages/jsp_templates that uses jstl tag library. It says to put a tag like this:

<%@ taglib uri='/WEB-INF/tlds/template.tld' prefix='template' %>

但是我收到错误(因为jstl.jar和standard.jar在WEB-INF / lib /中目录)。

but I get error (because jstl.jar and standard.jar are in WEB-INF/lib/ directory).

然而有人说jstl模板根据这个 Struts OR Tiles OR ??? ...... JSP模板解决方案

However some say jstl template have problems according to this Struts OR Tiles OR ???...... JSP template solution

我很乐意帮助我了解最好的方法。

I would be glad to help me know the best way.

编辑:我需要的是将页面的布局拆分成内容,标题, ...并在使用布局模板的页面中设置此部件,与asp母版页完全相同。

What I need is to split page's layout into parts like content, header,... and set this parts in the page that uses the layout template, exactly like asp master page.

推荐答案

Put WEB-INF / tags / genericpage.tag中的以下内容

Put the following in WEB-INF/tags/genericpage.tag

<%@tag description="Overall Page template" pageEncoding="UTF-8"%> <%@attribute name="header" fragment="true" %> <%@attribute name="footer" fragment="true" %> <html> <body> <div id="pageheader"> <jsp:invoke fragment="header"/> </div> <div id="body"> <jsp:doBody/> </div> <div id="pagefooter"> <jsp:invoke fragment="footer"/> </div> </body> </html>

要使用此功能:

<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="t" tagdir="/WEB-INF/tags" %> <t:genericpage> <jsp:attribute name="header"> <h1>Welcome</h1> </jsp:attribute> <jsp:attribute name="footer"> <p id="copyright">Copyright 1927, Future Bits When There Be Bits Inc.</p> </jsp:attribute> <jsp:body> <p>Hi I'm the heart of the message</p> </jsp:body> </t:genericpage>

这完全符合你的想法!

这是Will Hartung关于此链接的精彩答案的一部分。

This was part of a great answer by Will Hartung on this link.

更多推荐

创建JSP布局模板的最佳方法是什么?

本文发布于:2023-07-17 06:43:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130506.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:布局   模板   方法   JSP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!