1. TagLib的運用(Spring Security)
在web.xml中添加:
<servlet>
<servlet-name>JSPSupportServlet</servlet-name>
<servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
在頁面的最上面添加<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />
使用的時候:
<@security.authorize ifAnyGranted="ROLE_USER,ROLE_ADMIN">
Hello
</@security.authorize>
注意中間用的是句號,而不再是冒號,我一開始在這里沒注意,花了不少時間解決這個問題
2. Context Path的取得
在Google中搜了一下,有人提問題,但是沒有得到解決,后來查資料才知道應該是這樣寫的:
${request.contextPath}
3. 字符串的比較
字符串不能直接比較大小,我原來兩個日期字符串的比較就需要先轉換成日期型
<#if dateString1?date("yyyy-MM-dd HH:mm:ss") < dateString2?date("yyyy-MM-dd HH:mm:ss")>
日期小
</#if>
4. <#if><#else>
在if比較時小于號可以直接使用,但是大于號不行,要寫成
<#if a > b>
</#if>
5. 在jfinal中使用map
在jfinal中如果像通常情況下使用map, <#list map?keys as key> ${key} </#list>
會發現不僅是所有鍵值,所有的java方法名也被打印出來,比如:hashcode, getClass, put, get, clone, equals, containsKey, values等等。
正確的方法是:
<#list map.keySet() as key>
${key}
</#list>
if the key of the map is not String, such as Integer or other types,
we can access the value of the map by map.get( 1 ) instead of map[1]