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

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

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

    我的漫漫程序之旅

    專注于JavaWeb開發
    隨筆 - 39, 文章 - 310, 評論 - 411, 引用 - 0
    數據加載中……

    Struts2中的鏈接標簽

    為了使從一個頁面中鏈接一個動態數據變得簡單,Struts2框架提供了一系列的標簽。
    Struts2標簽的一種用法是創建鏈接到其他Web資源,特別是針對那些在本地應用中的資源。
     
    1.普通鏈接
    Web程序中最普通的應用是鏈接到其他頁面,下面看Welcome.jsp。
    <%@ page contentType="text/html; charset=UTF-8" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <html>
    <head>
        
    <title>Welcome</title>
        
    <link href="<s:url value="/css/tutorial.css"/>" rel="stylesheet"
              type="text/css"/>
    </head>
     
    <body>
    <h3>Commands</h3>
    <ul>
        
    <li><href="<s:url action="Login_input"/>">Sign On</a></li>
        
    <li><href="<s:url action="Register"/>">Register</a></li>
    </ul>
     
    </body>
    </html>

    1.1說明
    1.<%@ taglib prefix="s" uri="/struts-tags" %>
    此句表示導入struts標簽,并以s為前綴。即以s為前綴的標簽均來自struts標簽庫。
     
    2.<link href="<s:url value="/css/tutorial.css"/>" rel="stylesheet" type="text/css"/>
    此句表示利用url標簽導入一個路徑,鏈接到一個文件,注意此路徑為項目下的絕對路徑。
     
    3.<a href="<s:url action="Login_input"/>">Sign On</a>
    此句表示利用url標簽鏈接到一個action。
     
    1.2注冊action
    我們在struts.xml中注冊一個action來顯示welcome.jsp。

    <action name="Welcome">
           
    <result>/example/Welcome.jsp</result>
    </action> 

     

    注意此action注冊在package example下,所以在地址欄中敲入http://localhost:8080/StrutsHelloWorld/example/Welcome.action(StrutsHelloWorld是project名),會導向到Welcome.jsp。
     
    2.使用通配符
    對于上面的action注冊,我們也可以用下面的語句代替。

    <action name="*">
           
    <result>/example/{1}.jsp</result>
    </action>

    此句的意思是,如果在沒有找到匹配的action名稱的情況下,默認調用action名稱.jsp。第一句中星號指任意,而第二句中{1}指代第一句中星號指代的內容。

        舉個例子,如果在地址欄中敲入http://localhost:8080/StrutsHelloWorld/example/1.action,則系統查找struts.xml,發現沒有name為1的action,即最后調用name為星號的這個action,根據此action,將輸出/example/1.jsp。


    或者讀者可以直接點擊Welcome.jsp中的兩個超鏈接,系統將會報錯找不到Login_input.jsp和Register.jsp。因為這兩個action還沒有注冊,也沒有相應的jsp文件。
     
    3.帶參數的鏈接
    超鏈接后面帶有參數大家不會陌生,諸如http://www.apache.com/?language=ch。這個鏈接后面帶有一個language參數,其值為ch。你可以通過request.getParameter(“language”)找到參數值。下面演示在struts2中如何設置帶參數的鏈接??碒elloWorld.jsp。

    <%@ taglib prefix="s" uri="/struts-tags"%>
     
    <html>
    <head>
    <title>Hello World!</title>
    </head>
    <body>
    <h2><s:property value="message" /></h2>
    <h3>Languages</h3>
    <ul>
           
    <li>
             
    <s:url id="url" action="HelloWorld">
                  
    <s:param name="request_locale">en</s:param>
             
    </s:url>
             
    <s:a href="%{url}">English</s:a>
           
    </li>
           
    <li>
             
    <s:url id="url" action="HelloWorld">
                  
    <s:param name="request_locale">es</s:param>
             
    </s:url>
             
    <s:a href="%{url}">Espanol</s:a>
           
    </li>
    </ul>
     
    </body>
    </html>
    3.1說明
    1.<s:url id="url" action="HelloWorld">
                  <s:param name="request_locale">en</s:param>
    </s:url>
    此段表示設置一個url標簽指向名為HelloWorld的action,此標簽帶一個id取名為url,后面會用到。帶一個參數request_locale,其值為en。
     
    2.<s:a href="%{url}">English</s:a>
    此句用到了struts2的超鏈接標簽,連接的地址即為1中url,點擊English,發出的信息為:http://localhost:8080/StrutsHelloWorld/example/HelloWorld.action?request_locale=en
     
    3.2注冊action到struts.xml
    <struts>
           
    <package name="example" namespace="/example"
                  extends
    ="struts-default">
                  
    <action name="HelloWorld" >
                         
    <result>/example/HelloWorld.jsp</result>
                  
    </action>



    posted on 2007-11-26 23:52 々上善若水々 閱讀(2212) 評論(0)  編輯  收藏 所屬分類: Struts2

    主站蜘蛛池模板: 亚洲成人免费网址| 免费大黄网站在线观| 亚洲一区二区三区高清不卡| 嫩草影院免费观看| 中文字幕在线免费视频| 亚洲日韩乱码中文无码蜜桃| 日本免费一区尤物| 久久国产精品成人免费| 亚洲色偷偷综合亚洲AV伊人蜜桃 | 一级一黄在线观看视频免费| 国产精品亚洲片在线| 国内精品乱码卡1卡2卡3免费| 羞羞网站在线免费观看| 亚洲高清在线播放| 免费人成在线观看网站品爱网日本| 国产成人免费视频| 免费国产草莓视频在线观看黄| 亚洲精品美女久久久久9999| www.亚洲精品| 成人免费一级毛片在线播放视频 | 黄网站色视频免费看无下截| 亚洲精品高清视频| 亚洲国产高清精品线久久| 亚洲人成在线免费观看| aa级毛片毛片免费观看久| 亚洲av无码专区在线电影天堂 | 亚洲熟伦熟女新五十路熟妇| a拍拍男女免费看全片| 成在人线av无码免费高潮水| 亚洲国产成人AV在线播放| 亚洲尹人香蕉网在线视颅| 亚洲国产日韩成人综合天堂 | 亚洲福利精品电影在线观看| 和日本免费不卡在线v| 日本免费高清视频| 亚洲免费日韩无码系列| 欧美亚洲精品一区二区| 色在线亚洲视频www| 日韩亚洲AV无码一区二区不卡| 亚洲日本一区二区一本一道| 最近最好的中文字幕2019免费|