原来一直用struts,最近项目里有人用jstl,我也就顺便拿来用,感觉还是不错。
过程中碰到一些小的问题总结如下:
一。版本问题
jstl存在1.0和1.1的差异问题,用EL建议需要在1.1的版本下,1.1的URI的标志为:
<%
@ taglib uri
=
"
http://java.sun.com/jsp/jstl/core
"
prefix
=
"
c
"
%>
<%
@ taglib uri
=
"
http://java.sun.com/jsp/jstl/functions
"
prefix
=
"
fn
"
%>
注意,1.0版本没有/jsp/.
如果用的1.0会出现如下异常
org.apache.jasper.JasperException:
/
public
/
left_tree.jsp(
100
,
24
) According to TLD or attribute directive in tag file, attribute items does not accept any expressions
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:
510
)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
375
)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:
314
)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:
264
)
javax.servlet.http.HttpServlet.service(HttpServlet.java:
802
)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:
75
)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:
77
)
com.wellsoon.zfzw.webapp.common.VabAccessFilter.doFilter(VabAccessFilter.java:
43
)
root cause
二。打开EL
<%
@ page contentType
=
"
text/html;charset=gb2312
"
language
=
"
java
"
isELIgnored
=
"
false
"
%>
前提是容器支持2.0,即使支持默认也未必打开,最安全的方式就是显示打开 isELIgnored="false"
三.fn的用法
对于Vo里的一个List作length的计算或判断很方便
<
table
width
="160"
border
="0"
cellspacing
="0"
cellpadding
="4"
>
<
c:forEach
items
="${menuInfos}"
var
="m"
>
<
c:if
test
="${fn:length(m.subMenus)>0}"
>
<
tr
>
<
td
>
<
script
language
="JavaScript"
>
var
tObj
=
new
treeClass(
"
A1
"
)
tObj.start();
tObj.m_start(
"
<c:out value=
"
${m.menuModule}
"
/>
"
,
0
);
<
c:forEach items
=
"
${m.subMenus}
"
var
=
"
sub
"
>
tObj.add_Sub(
"
<c:out value=
"
${sub.menuName}
"
/>
"
,
"
<%=path%>
<c:out value=
"
${sub.url}
"
/>
"
,
"
mymain
"
);
</
c:forEach
>
tObj.m_end();
tObj.end();
tObj.print();
</
script
>
</
td
>
</
tr
>
</
c:if
>
</
c:forEach
>
</
table
>
四.tld的声明可以在web.xml作显式声明也可以用http作直接URL声明
推荐用本地的方式.