1. 程式人生 > >第八天:物件圖導航語言

第八天:物件圖導航語言

1Strust 取值                            EL 取值

#attr.age                                                                                           ${age}

#request.age                                                                                  ${requestScope.age}

#session.age                                                                                 ${sessionScope.age}

#application.age                                                                            ${applicationScope.age}

2、取值標籤:

<s:property value="#request.age"/>   相當於  <c:out/>

<s:property value="#request.age" default="預設值"/>   當取的之不存在時,顯示預設值

<s:property value="#request.age" escapeHtml="false"/> 格式化輸出

html

3、判斷標籤:

<s:if test=""(判斷條件)></s:if>

<s:elseif  test="" ></s:elseif>

<s:elseif  test=""></s:elseif>

<s:else></s:eles>

3、迭代標籤:

<s:iterator value="#request.list" var="list" status="n">

     <s:property value="#list"/><br/>

      </s:iterator>

4、常用UI標籤:

<s:date name="#request.now"  format="yyyy年MM月dd日--HH時mm分ss秒"/>
   <s:form method="post" action="">
   <s:textfield name="user.username" label="使用者" ></s:textfield>
   <s:password name="user.userpassword" label="密碼"></s:password>
   <s:radio list="{'男','女'}" name="user.usersex" label="性別"></s:radio>
   <s:radio list="#{1:'男',2:'女'}" name="user.usersex" label="性別2"></s:radio>
   <s:checkboxlist list="{'睡覺','吃飯','打遊戲','聽音樂'}" label="愛好" name="user.userlover"></s:checkboxlist>
   <s:checkboxlist list="#{1:'睡覺',2:'吃飯',3:'打遊戲',4:'聽音樂'}" label="愛好" name="user.userlover"></s:checkboxlist>
   <s:select list="{'遵義','西安','杭州','蘇州','雲南'}" name="user.useraddress" label="籍貫"></s:select>
   <s:select list="#{1:'遵義',2:'西安',3:'杭州',4:'蘇州',5:'雲南'}" name="user.useraddress" label="籍貫"></s:select>
   <s:submit value="提交"></s:submit>
   </s:form> 
   <hr/>
<s:optiontransferselect
     label="Favourite Cartoons Characters"
     name="leftSideCartoonCharacters"
     list="{'Popeye', 'He-Man', 'Spiderman'}"
     doubleName="rightSideCartoonCharacters"
     doubleList="{'Superman', 'Mickey Mouse', 'Donald Duck'}"
  />

  5、防止表單重複提交

  jsp介面:

<s:form method="post" action="login">
          <s:token></s:token>//防止表單重複提交核心標籤
          <s:textfield name="user.userName" label="使用者"></s:textfield>
          <s:password name="user.userPass" label="密碼"></s:password>
          <s:submit value="註冊"></s:submit>
</s:form>

配置檔案:

<action name="login" class="com.liu.action.LoginAction">
      <result>/success.jsp</result>
      <result name="invalid.token">/demo.jsp</result>
      <interceptor-ref name="token"></interceptor-ref>//使用token攔截器驗證是否重複提交
      <interceptor-ref name="defaultStack"></interceptor-ref>
</action>