如何用Struts的logic标签遍历一个list

sjzpc040529 2008-07-07 12:18:43
我想用Struts的loginc标签遍历一个list
list里面放的是vo对象,我现在已经吧list放到了session中
如何能在jsp页面得到list里面的对象的属性值呢
...全文
332 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lip009 2008-07-07
  • 打赏
  • 举报
回复
<table>
<logic:iterator id="item" name="list">
<tr>
<td><bean:write name="item" property="vo对象的属性名"/></td>
<td><bean:write name="item" property="vo对象的属性名"/></td>
<td><bean:write name="item" property="vo对象的属性名"/></td>
<td><bean:write name="item" property="vo对象的属性名"/></td>
</tr>
</logic:iterator>
</table>
sjzpc040529 2008-07-07
  • 打赏
  • 举报
回复
我感觉是自动加载action出的问题
bobor_2008 2008-07-07
  • 打赏
  • 举报
回复
应该是你的JSP代码写的有问题.

struts标签应该没有问题.
lip009 2008-07-07
  • 打赏
  • 举报
回复
全部的错误信息贴出来
sjzpc040529 2008-07-07
  • 打赏
  • 举报
回复
Source not found for JspServletWrapper.handleJspException(Exception) line: 473
就是这个错误,程序自动跳到debug下
Landor2004 2008-07-07
  • 打赏
  • 举报
回复
<logic:present name="TeaList" scope="session">
<logic:iterate id="it" name="TeaList" scope="session" type="com.xxx.Vo">
<bean:write name="it" property="teaId"/>
</logic:iterate>
</logic:present>

别忘了如果teaId是数字的话,要加上
<bean:write name="it" property="teaId" format="#"/>
lip009 2008-07-07
  • 打赏
  • 举报
回复
异常信息贴出来
sjzpc040529 2008-07-07
  • 打赏
  • 举报
回复
还是不行
我的页面代码
<%@ page contentType="text/html; charset=UTF-8" language="java" import="java.sql.*" errorPage="" %>
<jsp:directive.page import="com.zsw.ac.superadmin.vo.SuperAdmin"/>
<jsp:directive.page import="com.zsw.ac.editor.vo.Editor"/>
<jsp:directive.page import="java.util.List"/>
<%@ page import="com.zsw.ac.teacher.vo.Teacher"
%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
<head>
<html:base />

<title>editarticle.jsp</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" src="FCKeditor/fckeditor.js"></script>
</head>
<%
//Editor edt =(Editor)session.getAttribute("edt");
List teaList = (List)session.getAttribute("TeaList");
%>
<body>
<form id="form1" name="form1" method="post" action="default_do.jsp">
<logic:iterate id="it" name="TeaList">
<bean:write name="it" property="teaId"/>
</logic:iterate>
<table width="100%" border="0">
<tr>
<td>标题:<input type="text"></td>
</tr>
<tr>
<td>行业:<input type="text"></td>

</tr>
<tr>
<td>老师:<select name="tea" id="tea">
<option>--请选择--</option>





</select></td>

</tr>
<tr>
<td>价格:<input type="text"></td>

</tr>
<tr>
<td>状态</td>
</tr>
<tr>
<td height="25">
<textarea name="contest" id="contest" style="width:100%; height:400px;"></textarea>
<script type="text/javascript">
var oFCKeditor = new FCKeditor( 'contest' ) ;
//oFCKeditor.BasePath = 'FCKeditor/' ;
oFCKeditor.ToolbarSet = 'Default' ;
oFCKeditor.Width = '100%' ;
oFCKeditor.Height = '400' ;
oFCKeditor.Value = '' ;
oFCKeditor.ReplaceTextarea();
//oFCKeditor.Create() ;
</script>
<input type="submit" name="Submit" value="提交" />
</td>
</tr>
</table>
</form>

</body>
</html:html>
Action中的代码
TeacherService teaService = new TeacherService() ;
List list = null ;
list = teaService.queryAll() ;
HttpSession session = request.getSession() ;
session.setAttribute("TeaList", list);
String path ="addacticle";

return mapping.findForward(path);

zidasine 2008-07-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 lip009 的回复:]
HTML code<table>
<logic:iterator id="item" name="list">
<tr>
<td><bean:write name="item" property="vo对象的属性名"/></td>
<td><bean:write name="item" property="vo对象的属性名"/></td>
<td><bean:write name="item" property="vo对象的属性名"/></td>
<td><bean:write name="item" property="vo对象的属性名"/></td>
</tr>
</logic:iterator>
</table>
[/Quote]
正解
习惯加上scope属性
  • 打赏
  • 举报
回复
2楼
详解了


67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧