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

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

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

    迷失北京

    BlogJava 聯(lián)系 聚合 管理
      60 Posts :: 0 Stories :: 13 Comments :: 0 Trackbacks

    struts2標(biāo)簽

          終于把struts2標(biāo)簽看的差不多了,不過還有好多還不是很熟悉,我是結(jié)合Max的struts2教程和struts自帶的reference文檔學(xué)習(xí)的!筆記中有好多都是從Max的博客中搬來的。不過也沒有辦法,咱水平還不行,也只能站在人家的肩膀上學(xué)習(xí)一下了!!

          if,elseif, else標(biāo)簽

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'tags.jsp' starting page</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
      </head>
      
      <body>
      	<!-- 
      		小技巧:#parameters.country[1]可以這樣取值!原來Struts2是將URL傳的參數(shù)封裝 成一個(gè)數(shù)組的,
      		也就是說你可以在一個(gè)URL傳兩個(gè)同名的參數(shù)(即?name=a&name=b);
      	 -->
      	<%request.setCharacterEncoding("utf-8");%>
      	(request獲取方式)country=<%=request.getParameter("country") %><br>
      	<s:if test="#parameters.country[1] == 'www'">中國</s:if>
        <s:elseif test="#parameters.country[0] == '美國'">美國</s:elseif>
        <s:else >其他國籍的人</s:else>
      	<br>
      	
      	<!-- 為某個(gè)屬性賦值 -->
      	<s:set name="country" value="#parameters.country[1]"></s:set>
      	country=<s:property value="#country" /> <br> 	
        <s:if test="#country == 'www'">中國</s:if>
        <s:elseif test="#country == '美國'">美國</s:elseif>
        <s:else >其他國籍的人</s:else>
        <br>
      </body>
    </html>
    

      

    這里面有個(gè)小常識(shí),就是通過url傳遞參數(shù)的時(shí)候:Struts2是將URL傳的同名參數(shù)封裝成一個(gè)數(shù)組,也就是說我們可以在一個(gè)URL傳兩個(gè)同名的參數(shù)(即?name=a&name=b);獲取的時(shí)候直接#parameters.name[0], parameters.name[1]就可以分別取出兩個(gè)參數(shù)的值。

          include標(biāo)簽

      被包含頁面:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    this is the include page!!!

      包含頁面:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%
    	String path = request.getContextPath();
    	String basePath = request.getScheme() + "://"
    			+ request.getServerName() + ":" + request.getServerPort()
    			+ path + "/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    	<head>
    		<base href="<%=basePath%>">
    		<title>My JSP 'includea.jsp' starting page</title>
    		<meta http-equiv="pragma" content="no-cache">
    		<meta http-equiv="cache-control" content="no-cache">
    		<meta http-equiv="expires" content="0">
    		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    		<meta http-equiv="description" content="This is my page">
    		<!--
    	<link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">
    	-->
    	</head>
    	<body>
    		This is my JSP1 page.
    		<br>
    		<s:include value="include.jsp">
    			<!-- 提交表單時(shí)才會(huì)獲得value的值 -->
    			<s:param name="value1">test1</s:param>
    			<s:param name="value2" value="user"></s:param>
    		</s:include>
    	</body>
    </html> 

    當(dāng)然struts的include標(biāo)簽靜態(tài)動(dòng)態(tài)頁面都能包含的!

          i18n標(biāo)簽
    描述:加載資源包到值堆棧。它可以允許text標(biāo)志訪問任何資源包的信息,而不只當(dāng)前action相關(guān)聯(lián)的資源包。

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'tags3.jsp' starting page</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">
    	-->
      </head>
      
      <body>
      	 <!-- <s:text>標(biāo)簽沒弄明白 --> 
         <s:i18n name="I18N">
       		The i18n value is <s:text name="hi!!"></s:text>
    	 </s:i18n>
    	 <br>
    	 <s:debug></s:debug>
      </body>
    </html> 
    

      

          iterator標(biāo)簽   

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'tags2.jsp' starting page</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">
    	-->
      </head>  
      <% 
      	List<String> strs = new ArrayList<String>();
      	strs.add("a");
      	strs.add("b");
      	strs.add("c");
      	strs.add("d");
      	strs.add("e");  	
      	request.setAttribute("strs", strs);
      %>
      <body>
        <s:iterator value="#request.strs" var="strs">
        	<s:property value="#strs"/>
        </s:iterator>	
        <s:debug></s:debug>
      </body>
    </html>
    

      

    這個(gè)標(biāo)簽挺容易理解的。

          param標(biāo)簽

    struts2的<s: param>標(biāo)簽問我覺得比較復(fù)雜的。struts2的s:param標(biāo)簽主要有兩個(gè)屬性name與value, 若想在value屬性中輸入直接量,則可以這樣寫:<s:param name="some" value="%{'user'}"/>,  也可以這樣寫:<s:param name="some">user</s:param>。 但如果直接賦值,這個(gè)值不是由Action動(dòng)態(tài)生成的,而是自己指定的一個(gè)字符串,則只能用后者。

    param頁面代碼:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'param.jsp' starting page</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">
    	-->
      </head>
      
      <body>
      	<!-- struts2的s:param標(biāo)簽主要有兩個(gè)屬性name與value, 
      	若想在value屬性中輸入直接量,則可以這樣寫:<s:param name="some" value="%{'user'}"/>, 
      	也可以這樣寫:<s:param name="some">user</s:param>。
      	但如果直接賦值,這個(gè)值不是由Action動(dòng)態(tài)生成的,而是自己指定的一個(gè)字符串,則只能用后者。 -->
    	<s:url value="paramAction.jsp" id="href">
    		<s:param name="value1">hello!!</s:param>
    		<s:param name="valu2" value="%{'HELLO!'}"></s:param>
    	</s:url>
    	<s:a href="%{href}" mce_href="%{href}">paramAction</s:a>
    	<s:debug></s:debug>
      </body>
    </html>
    

      

    paramAction頁面:

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'paramAction.jsp' starting page</title>
        
    	<meta http-equiv="pragma" content="no-cache">
    	<meta http-equiv="cache-control" content="no-cache">
    	<meta http-equiv="expires" content="0">    
    	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    	<meta http-equiv="description" content="This is my page">
    	<!--
    	<link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css">
    	-->
      </head>
      
      <body>
        value1的值:<%=request.getParameter("value1") %><br>
        value1的值:<s:property value="#parameters.value1" /><br>
        value2的值:<%=request.getParameter("value2") %><br/><!-- 獲取不到值 -->
        value2的值:${#param.value2 }<!-- 獲取不到值 -->
        <s:debug></s:debug>
      </body>
    </html>
    

      

          經(jīng)常用到的UI標(biāo)簽

    <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>
    <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> 
    <html>
    <head>
        <title>UI Tags Example</title>
        <s:head />
         <sx:head parseContent="true"/>    
    </head>
    <body>
    <s:actionerror/>
    <s:actionmessage/>
    <s:fielderror />
    <s:form action="exampleSubmit" method="post" enctype="multipart/form-data" tooltipConfig="#{'jsTooltipEnabled':'true'}">
        <s:textfield 
                label="Name" 
                name="name"
                tooltip="Enter your Name here" />
    	<s:date name="Select Your Birthday"/>	
    	<!-- 在struts2.2.1中<sx:datetimepicker/>的標(biāo)簽使用有所變化,需要引入struts2-dojo-plugin-2.2.1.jar 
    		 這個(gè)包。	
    	-->
        <sx:datetimepicker
                tooltip="Select Your Birthday"
                label="Birthday"
                name="birthday" />
        <s:textarea
                tooltip="Enter your Biography"
                label="Biograph"
                name="bio"
                cols="20"
                rows="3"/>
        <s:select
                tooltip="Choose Your Favourite Color"
                label="Favorite Color"
                list="{'Red', 'Blue', 'Green'}"
                name="favoriteColor"
                emptyOption="true"
                headerKey="None"
                headerValue="None"/>
        <s:select
                tooltip="Choose Your Favourite Language"
                label="Favourite Language"
                list="#{'CN':'中文','EN':'英文','FR':'外文'}"
                name="favouriteLanguage"
                emptyOption="true"
                headerKey="None"
                headerValue="None"/>
        <s:checkboxlist
                tooltip="Choose your Friends"
                label="Friends"
                list="{'Patrick', 'Jason', 'Jay', 'Toby', 'Rene'}"
                name="friends"/>
        <s:checkbox
                tooltip="Confirmed that your are Over 18"
                label="Age 18+"
                name="legalAge"/>
        <s:doubleselect
                tooltip="Choose Your State"
                label="State"
                name="region" list="{'North', 'South'}"
                value="'South'"
                doubleValue="'Florida'"
                doubleList="top == 'North' ? {'Oregon', 'Washington'} : {'Texas', 'Florida'}" 
                doubleName="state"
                headerKey="-1"
                headerValue="---------- Please Select ----------"
                emptyOption="true" />
         <s:file
                tooltip="Upload Your Picture"
                label="Picture" 
                name="picture" />
                
        <s:optiontransferselect
                tooltip="Select Your Favourite Cartoon Characters"
                label="Favourite Cartoons Characters"
                name="leftSideCartoonCharacters" 
                leftTitle="Left Title"
                rightTitle="Right Title"
                list="{'Popeye', 'He-Man', 'Spiderman'}" 
                multiple="true"
                headerKey="headerKey"
                headerValue="--- Please Select ---"
                emptyOption="true"
                doubleList="{'Superman', 'Mickey Mouse', 'Donald Duck'}" 
                doubleName="rightSideCartoonCharacters"
                doubleHeaderKey="doubleHeaderKey"
                doubleHeaderValue="--- Please Select ---" 
                doubleEmptyOption="true"
                doubleMultiple="true" />
        
        <s:textarea
                label="Your Thougths"
                name="thoughts" 
                tooltip="Enter your thoughts here" />
                
        <s:submit onclick="alert('aaaa');" />
        <s:reset onclick="alert('bbbb');" />
    </s:form>
        
    </body>
    </html>
    

      

    這些代碼是直接從Max的博文中copy過來的,本來這是一個(gè)完整的例子我只是把前臺(tái)展示代碼考過來了。在這里有一個(gè)要注意的地方,不過在代碼中也有體現(xiàn),這是struts2比較高級(jí)的版本和低版本之間的區(qū)別,具體從哪個(gè) 版本改的我也不是很清楚。這個(gè)不同的用法是關(guān)于<s: datetimepicker>的。在使用<s: datetimepicker>時(shí),較高的版本中還必須引入struts2-dojo-plugin-2.2.1.jar,還得指明<%@ taglib prefix="sx" uri="/struts-dojo-tags" %> ,如果做實(shí)驗(yàn)不成功的可以考慮下是不是這個(gè)問題。

          struts-tags就算是復(fù)習(xí)到這里了,如果要是配合一個(gè)具體的項(xiàng)目的話就會(huì)更好了,繼續(xù)努力!!!

                                                                                                                                                                     

    posted on 2011-01-04 21:17 王康 閱讀(177) 評(píng)論(0)  編輯  收藏

    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲综合免费视频| 国产亚洲人成在线影院| 精品国产麻豆免费网站| xxxxx做受大片视频免费| 亚洲福利视频导航| 日韩一区二区免费视频| 免费无码黄网站在线看| 亚洲色无码专区一区| 亚洲国产精品无码专区| 在线jlzzjlzz免费播放| 国产啪精品视频网站免费尤物| 亚洲中文字幕无码一去台湾| 国产亚洲日韩在线三区| 手机在线免费视频| 国产成人无码区免费内射一片色欲| 亚洲日本VA中文字幕久久道具| 亚洲人成图片小说网站| 麻豆国产VA免费精品高清在线 | 亚洲黄色免费网址| 国产免费69成人精品视频| 18女人腿打开无遮掩免费| 一级做a爰片久久毛片免费陪| 亚洲丰满熟女一区二区v| 亚洲精品无码激情AV| 毛片免费全部免费观看| 99久久综合精品免费| 成人无码区免费A∨直播| 亚洲国产成人精品无码区花野真一| 99人中文字幕亚洲区| 国产成人亚洲综合无码| 国产免费131美女视频| 在线观看AV片永久免费| 无码专区AAAAAA免费视频| 一二三区免费视频| 日韩成人精品日本亚洲| 亚洲国产日韩精品| 亚洲成人在线免费观看| 久久久久亚洲Av片无码v | tom影院亚洲国产一区二区| 亚洲国产精品热久久| 亚洲另类激情综合偷自拍图|