📄 入門 26 - 使用xml管理tile配置資源 - javaworld@tw.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0071)http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=632 -->
<HTML><HEAD><TITLE>入門 26 - 使用XML管理Tile配置資源 - JAVAWORLD@TW</TITLE>
<META http-equiv=Content-Type content="text/html; charset=utf-8"><!-- CONFL-BEGIN standardHeader -->
<META http-equiv=Pragma content=no-cache>
<META http-equiv=Expires content=-1>
<SCRIPT language=javascript> var contextPath = '/confluence';</SCRIPT>
<LINK href="入門 26 - 使用XML管理Tile配置資源 - JAVAWORLD@TW.files/main-action.css"
type=text/css rel=stylesheet><LINK href="/confluence/images/icons/favicon.ico"
rel="shortcut icon"><LINK href="/confluence/images/icons/favicon.png"
type=image/png rel=icon>
<SCRIPT src="入門 26 - 使用XML管理Tile配置資源 - JAVAWORLD@TW.files/effects.js"></SCRIPT>
<!-- CONF-END standardHeader -->
<META content="MSHTML 6.00.2800.1491" name=GENERATOR></HEAD>
<BODY onload=placeFocus()>
<DIV id=Content>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=logocell width="60%" rowSpan=2>
<DIV class=spacenametitle><A
href="http://www.javaworld.com.tw/confluence/display/opensrc"><IMG
src="入門 26 - 使用XML管理Tile配置資源 - JAVAWORLD@TW.files/confluence_logo.gif"
align=bottom border=0></A> <A
href="http://www.javaworld.com.tw/confluence/display/opensrc">OpenSource
Project</A></DIV></TD>
<TD vAlign=top align=right width="40%">
<TABLE cellSpacing=1 cellPadding=2 align=right bgColor=#ffffff border=0>
<TBODY>
<TR>
<TD class=navItem onmouseover="this.className='navItemOver'"
onclick="window.document.location='/confluence/'"
onmouseout="this.className='navItem'" vAlign=center noWrap
align=middle> <A title="Go to the Confluence Dashboard"
accessKey=h onclick="return false"
href="http://www.javaworld.com.tw/confluence/"><U>H</U>OME</A>
</TD>
<TD class=navItem onmouseover="this.className='navItemOver'"
onclick="window.document.location='/confluence/spaces/listspaces.action'"
onmouseout="this.className='navItem'" vAlign=center noWrap
align=middle> <A title="The spaces available for you"
accessKey=s onclick="return false"
href="http://www.javaworld.com.tw/confluence/spaces/listspaces.action"><U>S</U>PACES</A>
</TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD vAlign=bottom align=right><SPAN class=smalltext><A
href="http://www.javaworld.com.tw/confluence/login.action?os_destination=/pages/viewpage.action?pageId=632">Log
In</A> </SPAN><A
href="http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=632&decorator=printable"><IMG
title="View a printable version of the current page." height=16
alt="View a printable version of the current page." hspace=1
src="入門 26 - 使用XML管理Tile配置資源 - JAVAWORLD@TW.files/print_16.gif" width=16
align=absMiddle vspace=1 border=0></A> <A
href="http://confluence.atlassian.com/display/DOC"><IMG
title="Get help from the Confluence website." height=16
alt="Get help from the Confluence website." hspace=1
src="入門 26 - 使用XML管理Tile配置資源 - JAVAWORLD@TW.files/help_16.gif" width=16
align=absMiddle vspace=1 border=0></A> </TD></TR></TBODY></TABLE><!-- CONF-BEGIN breadcrumbsAndSearch -->
<DIV class=breadcrumbs width="100%">
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD> Location: <A
href="http://www.javaworld.com.tw/confluence/dashboard.action">Dashboard</A>
> <A
href="http://www.javaworld.com.tw/confluence/spaces/viewspacesummary.action?key=opensrc">opensrc</A>
> <A
href="http://www.javaworld.com.tw/confluence/pages/listpages.action?key=opensrc">Pages</A>
> <A
href="http://www.javaworld.com.tw/confluence/display/opensrc/Home">Home</A>
> <A
href="http://www.javaworld.com.tw/confluence/display/opensrc/Struts">Struts</A>
> <A
href="http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=1958">Struts入門</A>
> <A
href="http://www.javaworld.com.tw/confluence/pages/viewpage.action?pageId=632">入門
26 - 使用XML管理Tile配置資源</A> </TD>
<FORM name=searchForm action=/confluence/dosearchsite.action
method=get><INPUT type=hidden value=true name=quickSearch>
<TD vAlign=bottom align=right width=200><A style="TEXT-DECORATION: none"
href="http://www.javaworld.com.tw/confluence/searchsite.action"><U>Q</U>uick
<U>Search</U></A>:<INPUT accessKey=q size=10 name=searchQuery.queryString><INPUT type=submit value=Go><BR><IMG height=1
src="入門 26 - 使用XML管理Tile配置資源 - JAVAWORLD@TW.files/spacer.gif"
width=200></TD></FORM></TR></TBODY></TABLE></DIV><!-- CONF-END breadcrumbsAndSearch -->
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD class=pagebody vAlign=top>
<DIV class=pageheader><SPAN class=pagetitle>入門 26 -
使用XML管理Tile配置資源</SPAN> </DIV>
<SCRIPT language=javascript> function toggle(id) { var oldAttachmentVersionsBlock = document.getElementById('attachment' + id); with (oldAttachmentVersionsBlock.style) { if ( display == "none" ) display = "" else display = "none" } var arrowIcon = document.getElementById('arrow' + id); with (arrowIcon) { if (src != null && (src.indexOf('/confluence/images/icons/arrow_closed_active_16.gif') != -1 || src.indexOf('/confluence/images/icons/arrow_closing_active_16.gif') != -1)) { src = '/confluence/images/icons/arrow_opening_active_16.gif'; } else { src = '/confluence/images/icons/arrow_closing_active_16.gif'; } } } </SCRIPT>
<DIV class=pagesubheading>Last changed on Oct 27, 2004 by <A
href="http://www.javaworld.com.tw/confluence/display/~koji">koji
lin</A> </DIV><!-- page content -->
<P
class=paragraph></P>在Tiles中,您可以使用XML或是JSP來管理版面配置的相關資源,這邊先介紹使用XML定義檔的方式,如之前主題所定義的,我們的定義檔是tiles-defs.xml,我們在當中如下撰寫:
<DIV class=code
style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
<DIV class=codeHeader
style="BORDER-BOTTOM-STYLE: solid"><B>tiles-defs.xml</B></DIV>
<DIV class=codeContent><PRE><?xml version=<SPAN class=java-quote>"1.0"</SPAN> encoding=<SPAN class=java-quote>"ISO-8859-1"</SPAN> ?>
<!DOCTYPE tiles-definitions PUBLIC
<SPAN class=java-quote>"-<SPAN class=java-comment>//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"</SPAN></SPAN>
<SPAN class=java-quote>"http:<SPAN class=java-comment>//jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd"</SPAN>></SPAN>
<tiles-definitions>
<definition name=<SPAN class=java-quote>".myLayout"</SPAN> path=<SPAN class=java-quote>"/tiles/myLayout.jsp"</SPAN>>
<put name=<SPAN class=java-quote>"title"</SPAN> value=<SPAN class=java-quote>"Sample Page Title"</SPAN> />
<put name=<SPAN class=java-quote>"header"</SPAN> value=<SPAN class=java-quote>"/tiles/header.jsp"</SPAN> />
<put name=<SPAN class=java-quote>"menu"</SPAN> value=<SPAN class=java-quote>"/tiles/menu.jsp"</SPAN> />
<put name=<SPAN class=java-quote>"footer"</SPAN> value=<SPAN class=java-quote>"/tiles/footer.jsp"</SPAN> />
<put name=<SPAN class=java-quote>"body"</SPAN> value=<SPAN class=java-quote>"/tiles/body.jsp"</SPAN> />
</definition>
</tiles-definitions></PRE></DIV></DIV><BR> 在<definition>標籤中,我們指定了版面配置的JSP頁面,也就是path屬性所指定的myLayout.jsp,name屬性表明這個版面配置的名稱,而在接下來的<put>標籤中,我們指定了內容頁面的名稱與JSP頁面實際的位置。<BR> Tiles的定義檔可以支援國際化,您可以複製以上的內容,撰寫在tiles-defs_zh.xml中,並將encoding改為big5,就可以在定義檔中使用中文,例如:
<DIV class=code
style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
<DIV class=codeHeader
style="BORDER-BOTTOM-STYLE: solid"><B>tiles-defs_zh.xml</B></DIV>
<DIV class=codeContent><PRE><?xml version=<SPAN class=java-quote>"1.0"</SPAN> encoding=<SPAN class=java-quote>"big5"</SPAN> ?>
<!DOCTYPE tiles-definitions PUBLIC
<SPAN class=java-quote>"-<SPAN class=java-comment>//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"</SPAN></SPAN>
<SPAN class=java-quote>"http:<SPAN class=java-comment>//jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd"</SPAN>></SPAN>
<tiles-definitions>
<definition name=<SPAN class=java-quote>".myLayout"</SPAN> path=<SPAN class=java-quote>"/tiles/myLayout.jsp"</SPAN>>
<put name=<SPAN class=java-quote>"title"</SPAN> value=<SPAN class=java-quote>"Tiles範例"</SPAN> />
<put name=<SPAN class=java-quote>"header"</SPAN> value=<SPAN class=java-quote>"/tiles/header.jsp"</SPAN> />
<put name=<SPAN class=java-quote>"menu"</SPAN> value=<SPAN class=java-quote>"/tiles/menu.jsp"</SPAN> />
<put name=<SPAN class=java-quote>"footer"</SPAN> value=<SPAN class=java-quote>"/tiles/footer.jsp"</SPAN> />
<put name=<SPAN class=java-quote>"body"</SPAN> value=<SPAN class=java-quote>"/tiles/body.jsp"</SPAN> />
</definition>
</tiles-definitions></PRE></DIV></DIV>
<P class=paragraph></P>其中myLayout.jsp的內容如下:
<DIV class=code
style="BORDER-TOP-STYLE: solid; BORDER-RIGHT-STYLE: solid; BORDER-LEFT-STYLE: solid; BORDER-BOTTOM-STYLE: solid">
<DIV class=codeHeader
style="BORDER-BOTTOM-STYLE: solid"><B>myLayout.jsp</B></DIV>
<DIV class=codeContent><PRE><%@taglib prefix=<SPAN class=java-quote>"tiles"</SPAN> uri=<SPAN class=java-quote>"/tags/struts-tiles"</SPAN>%>
<html>
<head><title><tiles:getAsString name=<SPAN class=java-quote>"title"</SPAN>/></title></head>
<body>
<table border=<SPAN class=java-quote>"0"</SPAN> width=<SPAN class=java-quote>"100%"</SPAN> cellspacing=<SPAN class=java-quote>"5"</SPAN>>
<tr>
<td colspan=<SPAN class=java-quote>"2"</SPAN>><tiles:insert attribute=<SPAN class=java-quote>"header"</SPAN>/></td>
<tr>
<tr>
<td width=<SPAN class=java-quote>"140"</SPAN> valign=<SPAN class=java-quote>"top"</SPAN>><tiles:insert attribute=<SPAN class=java-quote>"menu"</SPAN>/></td>
<td valign=<SPAN class=java-quote>"top"</SPAN> align=<SPAN class=java-quote>"left"</SPAN>><tiles:insert attribute=<SPAN class=java-quote>"body"</SPAN>/></td>
</tr>
<tr>
<td colspan=<SPAN class=java-quote>"2"</SPAN>><tiles:insert attribute=<SPAN class=java-quote>"footer"</SPAN>/></td>
</tr>
</table>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -