Jsp页面无法显示List数值debug4天经历-dayTwo
2013-01-10 16:39
465 查看
我觉得似乎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的代码 写法没有问题 。 问题出在其他方面 。
下班回家。
<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的代码 写法没有问题 。 问题出在其他方面 。
下班回家。
相关文章推荐
- Jsp页面无法显示List数值debug4天经历-dayFour
- Jsp页面无法显示List数值debug4天经历-dayOne
- Jsp页面无法显示List数值debug4天经历-dayThree
- 在JSP页面无法显示List集合.类似${list.size()},${user.getId()}的解决方法
- springMVC可以进入controller,jsp读取c标签无法读取值,直接显示${userList},
- java web程序升级jsp页面缓存无法显示最新的内容
- 三、在JSP页面对LIST对象级联显示
- Struts2的Action向JSP传输List集合并且将数据显示在页面上
- 关于JSP中动态包含请求无法显示页面的问题 post请求页面中包含get请求
- 关于在JSP中include其他页面后,dreamweaver的设计视图无法显示
- 在JSP页面中用select下拉列表来显示List列表的方式
- JAVA WEB开发从数据库中查询到的数据用list怎么在JSP页面整齐的显示出来,请写代码,
- jsp 页面无法正确显示后台数据 ,需多次刷新才能正确显示 在springmvc
- jsp 文本框不可编辑,禁止文本框的输入,JSP页面中的文本框只显示内容,而用户无法修改
- myeclipse6.5 debug 无法进入jsp页面
- jsp页面无法显示图片
- list数据显示到jsp页面和EL表达式的判断
- 实现在JSP页面对LIST对象级联显示
- JSP页面使用ie6打开时出现无法显示 XML 页
- 在服务器调试过程中,JSP页面无法正常显示