使用JSTL改写JSP页面.

luhongjun 2010-10-18 08:27:39
下面的JSP,怎样用JSTL改写.

<%
Vector list = (Vector) session.getAttribute("foldvector");
if(null == list) {
return;
}
for (int i = 0; i < list.size(); i++) {
Fold fold = (Fold) list.get(i);
String Mlmc=fold.getMlmc();
String index=String.valueOf(i);
%>

<a href="subMenu.jsp?Mldh=<%=index%>" target="left" ><span><%=Mlmc%></span></a>

<%
}
%>


主要是 Fold fold = (Fold) list.get(i); 增样用jstl表示.

...全文
123 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
blazingfire 2010-10-18
搞错了,用这个

<c:forEach items="${sessionScope.foldvector}" var="fold" varStatus="sList">

<a href="subMenu.jsp?Mldh=${sList.index}" target="left" >
<span>${fold.mlmc}</span></a>

</c:forEach>
  • 打赏
  • 举报
回复
blazingfire 2010-10-18
要用javabean属性,也就是o.getAbc() getter方法在el中就写成{o.abc}
<c:forEach items="${sessionScope.foldvector}" var="fold" varStatus="sList">

<a href="subMenu.jsp?Mldh=${sList.index}" target="left" >
<span>${list.mlmc}</span></a>

</c:forEach>

  • 打赏
  • 举报
回复
luhongjun 2010-10-18
<c:forEach items="${sessionScope.foldvector}" var="list" varStatus="sList">
<a href="subMenu.jsp?Mldh=${sList.index}" target="left" ><span>${list.mlmc}</span></a>
</c:forEach>

直接引用是出错的:(如果把${list.mlmc}换成字符可以正常运行)转化还是不对
Servlet.service() for servlet jsp threw exception
javax.el.ELException: Cannot convert [com.sinew.javabean.Fold@917cb0, com.sinew.javabean.Fold@1913751, com.sinew.javabean.Fold@c6b80e, com.sinew.javabean.Fold@5dc268, com.sinew.javabean.Fold@1866417, com.sinew.javabean.Fold@1526e3, com.sinew.javabean.Fold@ac2d3c] of type class java.util.Vector to class java.lang.Integer
at org.apache.el.lang.ELSupport.coerceToNumber(ELSupport.java:290)
at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:410)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:188)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:935)
at org.apache.jsp.mainMenu_jsp._jspx_meth_c_005fforEach_005f0(mainMenu_jsp.java:183)
at org.apache.jsp.mainMenu_jsp._jspService(mainMenu_jsp.java:148)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
  • 打赏
  • 举报
回复
sound9world 2010-10-18
[Quote=引用 1 楼 luhongjun 的回复:]

<c:forEach items="${sessionScope.foldvector}" var="list" varStatus="sList">

<a href="subMenu.jsp?Mldh=${sList.getIndex()}" target="left" ><span>${list.getMlmc()}</span></a>

</c:forEach>
……
[/Quote]
试试看不调用getter,直接${fold.mlmc} ,或许可行。
  • 打赏
  • 举报
回复
sound9world 2010-10-18

<c:forEach var="fold" items="${list}"></c:forEach>

可以试试这样,fold应该就是Fold fold = (Fold) list.get(i);
下面再使用就EL表达式如${fold.mlmc}这样

没有测试 希望能有所帮助
  • 打赏
  • 举报
回复
luhongjun 2010-10-18
<c:forEach items="${sessionScope.foldvector}" var="list" varStatus="sList">

<a href="subMenu.jsp?Mldh=${sList.getIndex()}" target="left" ><span>${list.getMlmc()}</span></a>

</c:forEach>

list没有使用Fold fold = (Fold) list.get(i); 直接使用list.getMlmc()是有问题的.
  • 打赏
  • 举报
回复
相关推荐
发帖
Web 开发

8.0w+

社区成员

Java Web 开发
社区管理员
  • Web 开发社区
加入社区
帖子事件
创建了帖子
2010-10-18 08:27
社区公告
暂无公告