jsp根据后台数据动态创建table中td的个数
2016-01-24 · 做真实的自己 用良心做教育
jsp根据数据动态生成table元素:
在test1中的body内的代码为:
<form action="test2.jsp">
row:<input type = "text" name="row">
col:<input type ="text" name="col">
<input type = "submit" value="submit">
</form>
在test2中的代码
<body>
<%! int a=1; %>
This is my JSP page. <br>
<% int row = 0;
int shu = 0;
row = Integer.parseInt(request.getParameter("row"));
shu = Integer.parseInt(request.getParameter("col"));
%>
<table align ="center" border=1 width=80%>
<%for(int i = 0;i<row;i++){
%>
<tr>
<%for(int j=0;j<shu;j++){%>
<td>
<%=a++ %>
</td>
<%} %>
</tr>
<%}%>
</table>
</body>
运行结果:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:if test="${list!= null || fn:length(list) != 0}">
<c:foreach items ="${lis}" var = "li " begin="0" end ="${fn:length(list) }">
<td></td>
</c:foreach>
</c:if>