Jsp页面无法显示List数值debug4天经历-dayTwo

来源:互联网 发布:dva防御矩阵启动英文 编辑:程序博客网 时间:2024/04/29 06:28

我觉得似乎table 内容似乎无法显示,修改代码如下:

<c:forEach begin="0" end = "1" var="i">
<tr>
   <th>${i}</th>
<!--    <th>${Role.id}</th>
<th>${Role.accountId}</th>
<th>${Role.name}</th>
<th>${Role.level}</th>
<th>${Role.isOnline}</th>
-->
</tr>
      </c:forEach>


页面可以显示table 的项目 。 i = 1, i =2 ,

重新改回来:

<c:forEach var="Role" items = "${RoleList}">
<tr>
   <th>${i}</th>
  <th><c:out value="${Role.name}" /></th>
<!-- <th>${Role.accountId}</th>
<th>${Role.name}</th>
<th>${Role.level}</th>
<th>${Role.isOnline}</th>
-->
</tr>
</c:forEach>

页面同样无法显示。 怀疑C标签的写法有问题 , 看struts 文档 , 改用 s标签 遍历iterator

  <s:iterator value="#request.RoleList" var="strs">
        <s:property value="#strs"/>

同样无法显示 , 改回C标签,发现自己的代码还有格式问题    将<th>改成<td>

<c:forEach var="Role" items="${RoleList}">
<tr>
<td>fortest</td>
<td>${Role.accountId}</td>
<td>${Role.name}</td>
<td>${Role.level}</td>
<td>${Role.isOnline}</td>
</tr>
</c:forEach> 

       问题一直是table的内容无法显示! 包括  <td>fortest</td>这种直接显示的项目 。但是 明明 List 的size又大于 0 。

<%

List <Role> RoleList = new ArrayList<Role>();
RoleList = (List<Role>)request.getAttribute("RoleList");
if(RoleList!=null){
for(Role role:RoleList){
int id = role.getAccountId();
String name = role.getName();
System.out.println(name);
}
}
%>

写了java代码又来验证 1 : List 能否取到值 , 2 : 能否取到List 里面的值 。 输出证明可以取到 name 。

还是怀疑C标签可能取不到值 ,(我以前没用过C标签)

改为自己最熟悉的混合代码:

<% if(RoleList!=null){
           int i = 0;
for(Role role:RoleList){
   i++; 
int id = role.getAccountId();
String name = role.getName();
System.out.println("wo are in circles,and the name is "+ name);
%>
<tr>
   <td>${name}</td>
   <td><%="name"%></td>
   <td><%=name%></td>
   <td><%=role.getName()%></td>
</tr>              
<%
}
}
%>

结果控制台会输出 :wo are in circles,and the name is XXX . 

显然,变量取到了值,但是却没有显示出来。我冤枉了 jstl core 标签 。 jstl 除了有core标签,还有另外3个标签库。

C 或者 S ,都是引用 的标记"prefix" 。我是绝对的jsp小白 一个。 

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="/struts-tags" prefix="s"%>  

不过这天我确认了遍历 List的代码 写法没有问题 。 问题出在其他方面 。

下班回家。

原创粉丝点击