欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
JSTL與Struts的結合(十二)

JSTL與Struts的結合(十二)

分類(lèi):我的著(zhù)作

9.9.4  JSP部分:<logic:iterate><c:forEach>標簽

在第三章示例的showAttackSolution.jsp中出現了這樣的使用:

<logic:iterate name="allAttackSolution"

id="attackSolution"

type="struts.sample.cap1.sample3.entity.AttackSolution">

         <tr>

                   <td style="word-break: break-all;">

                            <bean:write property="attack_event_code" name="attackSolution" />

                   </td>

                   <td style="word-break: break-all;">

                            <bean:write property="attack_mean" name="attackSolution" />

                   </td>

                   <td style="word-break: break-all;">

                            <bean:write property="attack_action" name="attackSolution" />

                   </td>

                   <td style="word-break: break-all;">

                            <input type="button"

                    onclick="del(‘<%=attackSolution.getAttack_event_code()%>‘);"

value="<bean:message key="message.delete"/>">

                   </td>

         </tr>

</logic:iterate>

由于在Action中將顯示的內容作為ArrayList類(lèi)型的實(shí)例保存在request中,因此這段JSP頁(yè)面標簽的工作是:

1)利用<logic:iterate>標簽對保存在ArrayList實(shí)例中的所有對象進(jìn)行循環(huán)取得。

2ArrayList類(lèi)型實(shí)例中的對象為struts.sample.cap1.sample3.entity.AttackSolution類(lèi)型,AttackSolution Java類(lèi)中的變量屬性都有get、set方法,因此可以被認為是一個(gè)標準的JavaBean。利用<bean:write>標簽將AttackSolution實(shí)例的變量屬性讀取出來(lái),并顯示。

根據之前討論的“<logic:iterate>標簽被<c:forEach>標簽和EL表達式替換”,可以利用<c:forEach>標簽和EL表達式來(lái)修改該段JSP代碼。修改的方式有兩種:

q         完全使用<c:forEach>標簽和EL表達式來(lái)替換全部。

q         僅使用EL表達式來(lái)替換<bean:write>標簽。

1. <c:forEach>標簽和EL表達式

<c:forEach>標簽和EL表達式:

<c:forEach items="${requestScope.allAttackSolution}"

var="attackSolution">

         <tr>

                  <td style="word-break: break-all;" >

                            ${attackSolution.attack_event_code}

                   </td>

                   <td style="word-break: break-all;" >

                            ${attackSolution.attack_mean}

                   </td>

                   <td style="word-break: break-all;" >

                            ${attackSolution.attack_action}

                   </td>

                   <td style="word-break: break-all;" >

<input type="button"

onclick="del(‘${attackSolution.attack_event_code}‘);"

value="<bean:message key="message.delete"/>">

</td>

         </tr>

</c:forEach>

這種修改方式將屏棄Struts框架的<logic:iterate>標簽,而以<c:forEach>標簽來(lái)作為循環(huán)迭代的工作。它的最大優(yōu)點(diǎn)是無(wú)需關(guān)注集合中的對象類(lèi)型,只要保證該對象是一個(gè)標準的JavaBean就可以了。

2. 使用EL表達式來(lái)替換<bean:write>標簽

<logic:iterate name="allAttackSolution"

id="attackSolution"

type="struts.sample.cap1.sample3.entity.AttackSolution">

         <tr>

                   <td style="word-break: break-all;" >

                       ${attackSolution.attack_event_code}

                   </td>

                   <td style="word-break: break-all;" >

                       ${attackSolution.attack_mean}

                   </td>

                   <td style="word-break: break-all;" >

                       ${attackSolution.attack_action}

                   </td>

                   <td style="word-break: break-all;" >

<input type="button"

onclick="del(‘${attackSolution.attack_event_code}‘);"

value="<bean:message key="message.delete"/>">

</td>

         </tr>

</logic:iterate>

這種方式對原來(lái)的代碼沒(méi)有做多大的改動(dòng),依然會(huì )使用<logic:iterate>標簽來(lái)作為循環(huán)標簽。不過(guò)對于原來(lái)使用<bean:write>標簽做顯示功能的地方,摒棄了<bean:write>標簽而直接使用EL表達式。靈活的EL表達式對頁(yè)面顯示邏輯有很大幫助,這種方式比較適合熟悉<logic:iterate>標簽的程序設計者。

9.9.5  完整的JSP

下面看一個(gè)完整的修改后JSP頁(yè)面的代碼,注釋掉的是被替換之前的代碼,讀者可以比較一下兩種實(shí)現方法。請見(jiàn)例9.7。

9.7:修改后showAttackSolution.jsp。

<%@ page contentType="text/html; charset=utf-8"%>

<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<html>

  <head>

    <!-- 略過(guò)JavaScript部分 -->

...

  </head>

  <body>

   <em><bean:message key="message.attacksolutionDB"/></em><p>

   <table>

        <html:errors/>

    </table>

<bean:message key="message.attackcode"/>:

<input name="attack_event_codeC" value="" type="text"> 

<bean:message key="message.attackdesc"/>:

<TEXTAREA style="height:100" name=attack_meanC></TEXTAREA> 

<bean:message key="message.attacksolution"/>:

<TEXTAREA style="height:100" name=attack_actionC></TEXTAREA> 

    <p/>

    <html:form action="AddAttackSolutionAction.do">

        <html:hidden property="attack_event_code"/>

        <html:hidden property="attack_mean"/>

        <html:hidden property="attack_action"/>

        <input type="button" onclick="add();" value="<bean:message key="message.add"/>">

        <input type="button" 

onclick="search();"

value="<bean:message key="message.search"/>">

    </html:form>

    <table border=1 cellspacing=1 cellpadding=2>

        <tr>

            <td style="background-color: #808080;font-size: 12pt;color: #ffffff;font-weight:

 bold;line-height: 15pt;border: 1px solid #808080;">

                <bean:message key="message.attackcode"/>

            </td>

            <td style="background-color: #808080;font-size: 12pt;color: #ffffff;font-weight:

 bold;line-height: 15pt;border: 1px solid #808080;">

                <bean:message key="message.attackdesc"/>

            </td>

            <td style="background-color: #808080;font-size: 12pt;color: #ffffff;font-weight:

 bold;line-height: 15pt;border: 1px solid #808080;">

                <bean:message key="message.attacksolution"/>

            </td>

            <td style="background-color: #808080;font-size: 12pt;color: #ffffff;font-weight:

 bold;line-height: 15pt;border: 1px solid #808080;">

                <bean:message key="message.delete"/>

            </td>

        </tr>

        <!-- 沒(méi)有替換前的代碼 -->

        <!--

            <logic:notEmpty name="allAttackSolution">

                <logic:iterate name="allAttackSolution"

id="attackSolution"

type="struts.sample.cap1.sample3.entity.AttackSolution">

                    <tr>

                        <td style="word-break: break-all;" >

                            <bean:write property="attack_event_code"

name="attackSolution"/>

                        </td>

                        <td style="word-break: break-all;" >

                            <bean:write property="attack_mean" name="attackSolution"/>

                        </td>

                        <td style="word-break: break-all;" >

                            <bean:write property="attack_action" name="attackSolution"/>

                        </td>

                        <td style="word-break: break-all;" >

                            <input type="button"

onclick="del(‘

<bean:write

property="attack_event_code"

name="attackSolution"/>‘);"

value="<bean:message key="message.delete"/>">

                        </td>

                    </tr>

                </logic:iterate>

            </logic:notEmpty>

        -->

        

        <!-- 僅替換<bean:write>標簽的代碼 -->

        <!--

            <logic:notEmpty name="allAttackSolution">

                <logic:iterate name="allAttackSolution"

id="attackSolution"

type="struts.sample.cap1.sample3.entity.AttackSolution">

                    <tr>

                        <td style="word-break: break-all;" >

                            ${attackSolution.attack_event_code}

                        </td>

                        <td style="word-break: break-all;" >

                            ${attackSolution.attack_mean}

                        </td>

                        <td style="word-break: break-all;" >

                            ${attackSolution.attack_action}

                        </td>

                        <td style="word-break: break-all;" >

                            <input type="button"

onclick="del(‘${attackSolution.attack_event_code}‘);"

value="<bean:message key="message.delete"/>">

                        </td>

                    </tr>

                </logic:iterate>

            </logic:notEmpty>

        -->

       

        <!-- 替換后的實(shí)現代碼 -->      

        <c:if test="${(requestScope.allAttackSolution != null)

&& fn:length(requestScope.allAttackSolution) != 0}">

            <c:forEach items="${requestScope.allAttackSolution}" var="attackSolution">

                <tr>

                    <td style="word-break: break-all;" >

                        ${attackSolution.attack_event_code}

                    </td>

                    <td style="word-break: break-all;" >

                        ${attackSolution.attack_mean}

                    </td>

                    <td style="word-break: break-all;" >

                        ${attackSolution.attack_action}

                    </td>

                    <td style="word-break: break-all;" >

                        <input type="button"

                              onclick="del(‘${attackSolution.attack_event_code}‘);"

value="<bean:message key="message.delete"/>">

                    </td>

                </tr>

            </c:forEach>

        </c:if>

    </table>

  </body>

</html>

可以看到,在這個(gè)被修改的JSP頁(yè)面代碼中,利用了Struts框架提供的標簽來(lái)實(shí)現提交部分的工作以及國際化資源配置文件讀取顯示的工作,也利用JSTL的標簽庫和EL表達式來(lái)實(shí)現頁(yè)面邏輯部分的工作。

JSP頁(yè)面使用JSTL是一種規范,也是一件令人興奮的事情,因為它使JSP部分的程序設計變得更加有效合理。

9.10  本章回顧

在本章的介紹中,筆者花了很大一段來(lái)介紹JSTLEL表達式和標簽庫的工作,接著(zhù)也對Struts標簽庫和JSTL標簽庫中相類(lèi)似的標簽作了比較,最后還修改了第三章的示例來(lái)真正的將Struts框架和JSTL結合在了一起。

不得不說(shuō)的是,JSTL實(shí)在是很棒的技術(shù),它為JSP的程序設計者帶來(lái)了福音。

當在JSP頁(yè)面使用Java語(yǔ)言片段已經(jīng)成為了歷史,在JSP頁(yè)面自定義標簽庫已經(jīng)不成為時(shí)尚的今天,何不試試JSTL呢?

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Struts標簽
struts標簽之淺入深出 OBS [和訊博客]
Struts1.x系列教程(7):Logic標簽庫
創(chuàng )建JSP文件和ActionForm Bean
【轉】struts1標簽庫
開(kāi)源框架: Struts Gossip
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久