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

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

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

    迷失北京

    BlogJava 聯系 聚合 管理
      60 Posts :: 0 Stories :: 13 Comments :: 0 Trackbacks

    struts2標簽

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

          if,elseif, else標簽

    <%@ 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傳的參數封裝 成一個數組的,
      		也就是說你可以在一個URL傳兩個同名的參數(即?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>
      	
      	<!-- 為某個屬性賦值 -->
      	<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>
    

      

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

          include標簽

      被包含頁面:

    <%@ 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">
    			<!-- 提交表單時才會獲得value的值 -->
    			<s:param name="value1">test1</s:param>
    			<s:param name="value2" value="user"></s:param>
    		</s:include>
    	</body>
    </html> 

    當然struts的include標簽靜態動態頁面都能包含的!

          i18n標簽
    描述:加載資源包到值堆棧。它可以允許text標志訪問任何資源包的信息,而不只當前action相關聯的資源包。

    <%@ 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>標簽沒弄明白 --> 
         <s:i18n name="I18N">
       		The i18n value is <s:text name="hi!!"></s:text>
    	 </s:i18n>
    	 <br>
    	 <s:debug></s:debug>
      </body>
    </html> 
    

      

          iterator標簽   

    <%@ 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>
    

      

    這個標簽挺容易理解的。

          param標簽

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

    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標簽主要有兩個屬性name與value, 
      	若想在value屬性中輸入直接量,則可以這樣寫:<s:param name="some" value="%{'user'}"/>, 
      	也可以這樣寫:<s:param name="some">user</s:param>。
      	但如果直接賦值,這個值不是由Action動態生成的,而是自己指定的一個字符串,則只能用后者。 -->
    	<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>
    

      

          經常用到的UI標簽

    <%@ 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/>的標簽使用有所變化,需要引入struts2-dojo-plugin-2.2.1.jar 
    		 這個包。	
    	-->
        <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過來的,本來這是一個完整的例子我只是把前臺展示代碼考過來了。在這里有一個要注意的地方,不過在代碼中也有體現,這是struts2比較高級的版本和低版本之間的區別,具體從哪個 版本改的我也不是很清楚。這個不同的用法是關于<s: datetimepicker>的。在使用<s: datetimepicker>時,較高的版本中還必須引入struts2-dojo-plugin-2.2.1.jar,還得指明<%@ taglib prefix="sx" uri="/struts-dojo-tags" %> ,如果做實驗不成功的可以考慮下是不是這個問題。

          struts-tags就算是復習到這里了,如果要是配合一個具體的項目的話就會更好了,繼續努力?。。?/p>

                                                                                                                                                                     

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

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 在线播放高清国语自产拍免费| 50岁老女人的毛片免费观看| 一本色道久久88亚洲综合| 亚洲自偷自偷在线成人网站传媒| 欧洲一级毛片免费| 亚洲国产成人91精品| 毛片免费观看网址| 亚洲精品日韩一区二区小说| 成年性午夜免费视频网站不卡| 亚洲精品无码久久久久牙蜜区| 日日操夜夜操免费视频| 香蕉视频免费在线| 国产精品亚洲视频| 亚洲午夜免费视频| 亚洲一级毛片免费看| 午夜小视频免费观看| 鲁啊鲁在线视频免费播放| 国产精品亚洲A∨天堂不卡| 无码国产精品一区二区免费模式| 91亚洲自偷手机在线观看| 一本无码人妻在中文字幕免费| 亚洲女子高潮不断爆白浆| 亚洲成av人片在线观看天堂无码| 插鸡网站在线播放免费观看| 亚洲午夜精品久久久久久人妖| 国产四虎免费精品视频| 久久精品国产亚洲AV| 亚洲精品高清国产一线久久| 18勿入网站免费永久| 激情吃奶吻胸免费视频xxxx| 久久精品亚洲视频| 暖暖免费高清日本一区二区三区| jizz18免费视频| 亚洲综合久久久久久中文字幕| 国产三级在线观看免费| 国产免费区在线观看十分钟| 亚洲欧洲日产韩国在线| va亚洲va日韩不卡在线观看| 18禁成人网站免费观看| 四虎影视久久久免费| 亚洲宅男天堂a在线|