struts2中 標簽的使用


轉載:http://blog.sina.com.cn/s/blog_5f9938640100v2kr.html

A:<s:if>判斷字符串的問題: 1、判斷單個字符:<s:if test="#session.user.username=='c'"> 這樣是從session中取出username的值,並且判斷其是否為c,但是這樣判斷是不正確的,這樣判斷的話,根本判斷不出來,要改成下面這樣: <s:if test="#session.user.username=='c'.toString()"> 這樣判斷才能正確判斷,至於原因我也不知道,在網上看到struts2中可能它判斷的是char類型。 2、判斷字符串:<s:if test="#session.user.username=='milo'"> 這樣寫的就是判斷username是不是milo,是String的判斷,這個是不用加toString()的。 3、判斷數值:<s:if test="#session.user.username==0"> 這樣寫的就是判斷username是不是0,是int的判斷。 B:判斷為空的問題: <s:if test="#session.user.username==null"> struts2中的判空似乎只能這么寫 判斷非空可以這樣寫: <s:if test="#session.user.username!=null" > 舉例: <s:set name="name" value="model.userId" /> <s:if test="#name == 'luozhh'"> Luozhh's file here </s:if> <s:elseif test="#name == 'Scott'"> Scott's file here </s:elseif> <s:else> Other's file here </s:else>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM