日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Struts2中的链接标签 s:url和s:a

發(fā)布時間:2024/9/27 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Struts2中的链接标签 s:url和s:a 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2011-08-03 11:05:56|??分類:java web |??標簽: |字號 ?訂閱 普通鏈接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><a href="<s:url action="Login_input"/>">Sign On</a></li>???<li><a 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標簽鏈接到一個action1.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.actionStrutsHelloWorldproject名),會導向到Welcome.jsp。2.使用通配符對于上面的action注冊,我們也可以用下面的語句代替。
<action name="*">??????<result>/example/{1}.jsp</result></action>
此句的意思是,如果在沒有找到匹配的action名稱的情況下,默認調用action名稱.jsp。第一句中星號指任意,而第二句中{1}指代第一句中星號指代的內容。
????舉個例子,如果在地址欄中敲入
http://localhost:8080/StrutsHelloWorld/example/1.action,則系統(tǒng)查找struts.xml,發(fā)現(xiàn)沒有name1action,即最后調用name為星號的這個action,根據(jù)此action,將輸出/example/1.jsp
或者讀者可以直接點擊Welcome.jsp中的兩個超鏈接,系統(tǒng)將會報錯找不到Login_input.jspRegister.jsp。因為這兩個action還沒有注冊,也沒有相應的jsp文件。3.帶參數(shù)的鏈接超鏈接后面帶有參數(shù)大家不會陌生,諸如http://www.apache.com/?language=ch。這個鏈接后面帶有一個language參數(shù),其值為ch。你可以通過request.getParameter(“l(fā)anguage”)找到參數(shù)值。下面演示在struts2中如何設置帶參數(shù)的鏈接。看HelloWorld.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標簽指向名為HelloWorldaction,此標簽帶一個id取名為url,后面會用到。帶一個參數(shù)request_locale,其值為en2<s:a href="%{url}">English</s:a>此句用到了struts2的超鏈接標簽,連接的地址即為1url,點擊English,發(fā)出的信息為:http://localhost:8080/StrutsHelloWorld/example/HelloWorld.actionrequest_locale=en3.2注冊actionstruts.xml<struts>??????<package name="example" namespace="/example"?????????????extends="struts-default">?????????????<action name="HelloWorld" >????????????????????<result>/example/HelloWorld.jsp</result>
?????????????</action>
???????</package>
</struts>

總結

以上是生活随笔為你收集整理的Struts2中的链接标签 s:url和s:a的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。