jsp标签 <c:forEach>我怎么遍历不了哦
我的jsp页面<%@pagelanguage="java"import="java.util.*,loveDao.*,loveBean.*"pageEncoding="g...
我的jsp页面 <%@ page language="java" import="java.util.*,loveDao.*,loveBean.*" pageEncoding="gbk"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="user" scope="page" class="loveBean.users"/>
<jsp:useBean id="boarde" class="loveDao.boardDao" scope="page"/>
<jsp:setProperty property="*" name="user"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>TestJSTLlogin</title>
</head>
<%
ArrayList<board> alboard=boarde.selectBoard(0);
%>
<body>
<%
for(int i=0;i<alboard.size();i++)
{
out.print(alboard.get(i).getBoaradName());
}
%>
<c:out value="d"></c:out>
<c:forEach var="al" items="${alboard}">
<c:out value="${al.value.boardId}"></c:out>
</c:forEach>
登陆成功
</body>
</html>
上边的能打出来,用标签的就打不出!为什么哦?谁能帮我改改哦? 展开
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="user" scope="page" class="loveBean.users"/>
<jsp:useBean id="boarde" class="loveDao.boardDao" scope="page"/>
<jsp:setProperty property="*" name="user"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<title>TestJSTLlogin</title>
</head>
<%
ArrayList<board> alboard=boarde.selectBoard(0);
%>
<body>
<%
for(int i=0;i<alboard.size();i++)
{
out.print(alboard.get(i).getBoaradName());
}
%>
<c:out value="d"></c:out>
<c:forEach var="al" items="${alboard}">
<c:out value="${al.value.boardId}"></c:out>
</c:forEach>
登陆成功
</body>
</html>
上边的能打出来,用标签的就打不出!为什么哦?谁能帮我改改哦? 展开
4个回答
2011-01-11
展开全部
你在<%
ArrayList<board> alboard=boarde.selectBoard(0);
%>这一段代码中加入一句 将alboard对象放入作用域内
c:foreach是读取作用域中的内容
<%
ArrayList<board> alboard=boarde.selectBoard(0);
request.setAttribute("alboard",alboard);//放入request作用域也可以放入session 或 application
%>
ArrayList<board> alboard=boarde.selectBoard(0);
%>这一段代码中加入一句 将alboard对象放入作用域内
c:foreach是读取作用域中的内容
<%
ArrayList<board> alboard=boarde.selectBoard(0);
request.setAttribute("alboard",alboard);//放入request作用域也可以放入session 或 application
%>
展开全部
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="sql" uri="" %>
<%@ taglib prefix="fmt" uri="" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test1.jsp' starting page</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">
-->
</head>
<body>
This is my JSP page. <br>
<%
List<String> list = new ArrayList<String>();
String topic = new String("hello way");
for(int i= 0 ;i <3;i++)
{
topic += (i +"");
list.add(topic);
System.out.println("author:" + topic);
}
request.setAttribute("topicTest",list);
%>
<c:forEach items="$" var="topic">
$<br>
</c:forEach>
</body>
</html>
输出
This is my JSP page.
hello way0
hello way01
hello way012
<%@ taglib prefix="c" uri="" %>
<%@ taglib prefix="sql" uri="" %>
<%@ taglib prefix="fmt" uri="" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'test1.jsp' starting page</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">
-->
</head>
<body>
This is my JSP page. <br>
<%
List<String> list = new ArrayList<String>();
String topic = new String("hello way");
for(int i= 0 ;i <3;i++)
{
topic += (i +"");
list.add(topic);
System.out.println("author:" + topic);
}
request.setAttribute("topicTest",list);
%>
<c:forEach items="$" var="topic">
$<br>
</c:forEach>
</body>
</html>
输出
This is my JSP page.
hello way0
hello way01
hello way012
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
上面两位说的很清楚了。。 <c:forEach var="al" items="${alboard}"> 是获取作用域中的,也就是说想获取alboard,在前面或者后台要有一句 request.setAttribute("alboard",alboard); 反正就是在foreach之前就可以了。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ArrayList<board> alboard=boarde.selectBoard(0);
后面加上 request.setAttribute("alboard",alboard);就可以了
后面加上 request.setAttribute("alboard",alboard);就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询