<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 89,  comments - 98,  trackbacks - 0

    <html:link> 標(biāo)簽用于生成HTML <a> 元素。<html:link> 在創(chuàng)建超鏈接時,有兩個優(yōu)點(diǎn):
    (1) 允許在URL 中以多種方式包含請求參數(shù)。
    (2) 當(dāng)用戶瀏覽器關(guān)閉Cookie 時,會自動重寫URL,把SessionID 作為請求參數(shù)包含在URL 中,用于跟蹤用戶的Session 狀態(tài)。

    <html:link> 標(biāo)簽有以下重要屬性:
    (1) forward:指定全局轉(zhuǎn)發(fā)鏈接。
    (2) href:指定完整的URL 鍵接。
    (3) page:指定相對于當(dāng)前網(wǎng)頁的URL。

    ??????? <html:rewrite> 用于輸出超鏈接中的URI部分,但它并不生成HTML <a> 元素。URI指的是URL 中協(xié)議、主機(jī)和端口以后的內(nèi)容。URI 用于指定具體的請求資源。例如,對于URL:HTTP://localhost:8080/HtmlBasic.do,它的URI為/HtmlBasic.do

    示例:
    1、創(chuàng)建全局轉(zhuǎn)發(fā)鏈接
    ??? 首先,在Struts-config.xml 中<global-forwards> 元素中定義一個<forward> 元素:
    ??? <global-forwards>
    ??????? <forward name = "index" path="/index.jsp"/>
    ??? </global-forwards>
    ??? 接著,在JSP 文件中創(chuàng)建<html:link> 標(biāo)簽:
    ??? <html:link forward="index">
    ??????? Link to Global ActionForward
    ??? </html:link>
    ??? <html:link> 標(biāo)簽的forward 屬性和<global-forwards> 元素中的<forward> 子元素匹配。以上代碼生成如下HTML 內(nèi)容:
    ??? <a href="/index.jsp">Link to Global ActionFoward</a>
    ??? 值得注意的是,<html:link> 的forward 屬性只引用Struts-config.xml 配置文件中<global-forwards>內(nèi)的<forward> 子元素,如果引用<action> 內(nèi)的<forward> 子元素,在運(yùn)行時將會拋出異常:
    ??? Cannot create rewrite URL: Java.Net.MalfomedURlException: Cannot retrieve ActionForward

    2、創(chuàng)建具有完整URL 的鏈接
    ??? 如果Web 應(yīng)用需要鏈接到其他站點(diǎn),應(yīng)該給出其他站點(diǎn)完整URL,例如:
    ??? <html:link href="??????? Generate an "href" directly
    ??? </html:link>
    ??? 生成HTML 代碼如下:
    ??? <a href="
    an "href" directly</a>
    ??? 值得注意的是,如果指定了<html:link> 標(biāo)簽的href 屬性,即使用戶瀏覽器的Cookie 關(guān)閉,<html:link> 標(biāo)簽也不會把用戶SessionID 作為請求參數(shù)加和到URL 中。

    3、從當(dāng)前網(wǎng)頁中創(chuàng)建相對URL
    ??? 如果從一個網(wǎng)頁鏈接到同一個應(yīng)用中的另一網(wǎng)頁,可以采用以下方式:
    ??? <html:link page="/HtmlBasic.do">
    ??????? A relative link from this page
    ??? </html:link>
    ??? <html:link> 標(biāo)簽的 page 屬性用于指定相對于當(dāng)前應(yīng)用的URI。以上代碼生成如下HTML 內(nèi)容:
    ??? <a href="/lib/HtmlBasic.do">......</a>

    4、在URL 或 URI 中包含請求參數(shù)
    ??? 如果要在URL或URI 中包含請求參數(shù),只要把請求參數(shù)加在URL 或 URI的末尾就可以了。例如:
    ??? <html:link page="/HtmlBasic.do?prop1=abc&amp;prop2=123">
    ??????? Hard-code the url parameters
    ??? </html:link>
    ??? <!-- or -->
    ??? <html:rewrite page="/HtmlBasic.do?prop1=abc&amp;prop2=123"/>
    ??? 以上代碼生成如下HTML 內(nèi)容:
    ??? <a href=/lib/HtmlBasic.do?prop1=abc&amp;prop2=123">......</a>
    ??? rewrite: /HtmlBasic.do?prop1=abc&amp;prop2=123

    ??? 提示:在HTML 中&amp 代表特殊字符 "&"

    5、在URL 或 URI 中包含單個請求變量
    ?????????????????
    ??????? 如果要在URL 中包含一個請求參數(shù),而這人參數(shù)的值存在于當(dāng)前網(wǎng)頁可訪問的一個變量中,可以按以下方法來實(shí)現(xiàn)。
    ??????? 為了演示這一功能,首先創(chuàng)建一個當(dāng)前網(wǎng)頁可訪問的變量。例如,本例中創(chuàng)建了兩個變量,一個是字符類型,一個是CustomerBean , 它們存存于一個 page 范圍內(nèi):
    ??? <%
    ??????? /*
    ???????? * Create a string object to store as a bean in
    ???????? * the page content and embed in this link
    ???????? */
    ??????? String stringBean = "Value to Pass ont URL";
    ??????? pageContext.setAttribute("stringBean", stringBean);
    ??? %>
    ??? <jsp:useBean id = "customerBean" scope="page" class="htmltaglibs.beans.CurstomerBean"/>
    ??? <jsp:setProperty name="customerBean" property="name" value="weiqin"/>
    ??????? 接著,把這兩個變量作為請求參數(shù),加入到URL或URI 中:
    ??? <html:link page="/HtmlBasic.do"
    ????????????????????? paramId="urlParamName"
    ????????????????????? paramName="stringBean">
    ??????? URL encode a parameter based on a string bean value
    ??? </html:link>
    ??? <html:link page="/HtmlBasic.do"
    ?????????????????????? paramId="urlParamName"
    ?????????????????????? paramName="customerBean"
    ?????????????????????? paramProperty="name">
    ??????? URL encode a parameter based on a customer bean value
    ??? </html:link>

    ??? rewrite: <html:rewrite page="/HtmlBasic.do"
    ?????????????????????????????????????????? paramId="urlParamName" paramName="stringBean"/>
    ??? rewrite: <html:rewrite page="/HtmlBasic.do"???????????????????????????????????????????
    ?????????????????????????????????????????? paramId="urlParamName" paramName="customerBean"
    ?????????????????????????????????????????? paramProperty="name"/>

    ??? <html:link> 標(biāo)簽的 paramId 屬性指定請求參數(shù)名,paramName 屬性指定變量的名字。如果變量為JavaBean ,用paramProperty 屬性指定JavaBean 的屬性。
    ??? 對于本例的stringBean,請求參數(shù)值為stringBean 的字符串值。對于customerBean,指定了paramProperty 屬性,請求參數(shù)值為customerBean 的 name 屬性值。
    ??? 以上代碼生成如下HTML 內(nèi)容:
    ??? <a href="/HtmlBasic.do?urlParamName=Value to Pass on Url">
    ??????? Url encode a paramter based on a string bean value
    ??? </a>

    ??? <a href="/HtmlBasic.do?urlParamName=weiqin">
    ??????? url encode a parameter based on a customer bean value
    ??? </a>

    ??? rewrite: /HtmlBasic.do?urlParamName=Value to Pass on Url
    ??? rewrite: /HtmlBasic.do?urlParamName=weiqin
    6、在URL 或 URI 中包含多個請求變量
    ??? 如果在URL 或 URI 中包含多個請求參數(shù),而這些參數(shù)的值來自多個變量,需要先定義一個Map類型的java 類,如java.util.HashMap,用它來存放請求變量。例如:
    ??? <%
    ??????? /*
    ???????? * Strore values int a Map(HashMap in this case)
    ???????? * and construct the URL based on the Map
    ???????? * /
    ??????? java.util.HashMap myMap = new java.util.HashMap();
    ??????? myMap.put("myString", new String("myStringValue"));
    ??????? myMap.put("myArray" , new String[]{"str1","str2","str3"} );
    ??????? pageContext.setAttribute("map", myMap);
    ??? %>
    ??? 在以上代碼的HaspMap 中存放了兩個對象,其中第二個對象是個字符串?dāng)?shù)組。HashMap 被存放在PageContext 中。 接下來就可以把這個HashMap 作為請求參數(shù),加入到URL 或 URI 中:
    ??? <%-- For this version of the <html:link> tag: --%>
    ??? <%-- map = a map with name/value pairs to pass on the url --%>
    ??? <html:link page="/HtmlBasic.do" name="map">
    ??????? URL encode a parameter based on value in a Map
    ??? </html:link>
    ??? <%-- Create the same rewrite string for the above link. --%>
    ??? rewrite:<html:rewrite page="/HtmlBasic.do" name="map"/>

    ??? <html:link> 標(biāo)簽的name 屬性指定包含請求變量的HashMap 對象。HashMap 對象中的每一對"key/value" 代表一對或多對"請求參數(shù)名/請求參數(shù)值"。以上代碼生成如下的Html 內(nèi)容:
    ??? <a href="/HtmlBasic.do?myString=myStringValue&amp;myArray=str1&amp;myArray=str2&amp;myArray=str3">
    ??????? URL encode a parameter based on value in a Map
    ??? </a>
    ???
    ??? rewrite:/HtmlBasic.do?myString=myStringValue&amp;myArray=str1&amp;myArray=str2&amp;myArray=str3

    ??????

    ?


    FeedBack:
    # re: Struts -- html:link 標(biāo)簽的使用
    2007-02-08 13:28 | 水煮三國
    <html:link action="abc"/>
    也是可以的.
    不過如果有action就不必加abc.do這樣的后綴了,只須abc即可.
    但是page就必須加上.do  回復(fù)  更多評論
      
    <2006年11月>
    2930311234
    567891011
    12131415161718
    19202122232425
    262728293012
    3456789

    常用鏈接

    留言簿(4)

    隨筆分類(85)

    隨筆檔案(89)

    文章分類(14)

    文章檔案(42)

    收藏夾(37)

    java

    oracle

    Sybase

    搜索

    •  

    積分與排名

    • 積分 - 210795
    • 排名 - 266

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 狠狠色伊人亚洲综合网站色| 99精品视频免费| 亚洲精品456播放| a级日本高清免费看| 亚洲综合久久成人69| 处破痛哭A√18成年片免费| 产传媒61国产免费| 亚洲人成网站在线观看播放动漫| 国产色爽女小说免费看| 免费无码中文字幕A级毛片| 亚洲αⅴ无码乱码在线观看性色| 中文字幕不卡亚洲 | 国内精品久久久久影院亚洲| 久久久久久久亚洲精品| 免费可以在线看A∨网站| japanese色国产在线看免费| 亚洲成人午夜电影| 中文字幕日韩亚洲| 好吊妞在线成人免费| 99精品免费观看| 午夜不卡AV免费| 亚洲 欧洲 自拍 另类 校园| 亚洲va久久久噜噜噜久久男同 | 婷婷亚洲天堂影院| 国产精品1024永久免费视频| 精品一区二区三区免费视频 | 成人免费午夜无码视频| 黄色网页在线免费观看| 亚洲精品美女久久7777777| 亚洲首页在线观看| 亚洲熟女少妇一区二区| 免费人成在线观看播放国产 | 中文字幕在线成人免费看| 亚洲精品永久在线观看| 亚洲福利视频网站| 久久精品国产亚洲av麻| 中文字幕亚洲日本岛国片| 日本免费观看网站| 国产成人A在线观看视频免费| 在线日本高清免费不卡| 国产成人AV免费观看|