首页 > Web开发 > 详细

jsp输出显示表格

时间:2014-02-20 18:22:59      阅读:382      评论:0      收藏:0      [点我收藏+]

1.定义输出显示表格行数和列数表单叶

bubuko.com,布布扣
 1 <html>
 2    <head>
 3    <title>我的</title>
 4    </head>
 5    <body>
 6    <form action="print_table.jsp" method="post">
 7    <table border="1"width="100%">//border是显示不显示边框的问题,0代表不显示出来,1代表显示出来  100%是网站采用百分比制作后,可适应浏览者机器的任意屏幕分辨率尺寸,
 8  <tr>
 9    <td>输入要显示的表格行数</td>
10    <td><input type="text" name="row"></td>
11  </tr>
12       <tr>
13       <td>输入要显示表格的列数</td>
14       <td><input type="text" name="col"></td>
15      </tr>
16  <tr>
17 <td colspan="2">                 //而colspan是这个列跨度为两列的位置,说白点,就是取消了这两个列中间的横线,变成了一个列
18   <input type="submit" value="显示">
19   <input type="reset" value="重置">
20 </td>
21    </tr>
22  
23        </table>
24      </form>
25    </body>
26 </html>
bubuko.com,布布扣

2.处理表格显示

bubuko.com,布布扣
 1 <html>
 2   <head><title>表格</title></head>
 3   <body>
 4   <table border="1"width="100%">
 5   <%
 6   int rows=0;
 7   int cols=0;
 8      try{
 9          rows=Integer.parseInt(request.getParameter("row"));   //Integer.parseInt转化成整形否则抛出异常,request.getParameter接受来自htm表单的数据,括号里指name
10          cols=Integer.parseInt(request.getParameter("col"));
11      }catch(Exception e){}
12     for(int x=0;x<rows;x++){
13   %>
14   <tr>
15   <%
16          
17        for(int y=0;y<cols;y++){
18   %>
19   <td><%=(x*y)%></td>
20   <%
21        }
22   %>
23   </tr>
24   <%
25      }
26   %>
27   </table>
28     </body>
29   </html>
bubuko.com,布布扣

jsp输出显示表格

原文:http://www.cnblogs.com/anuo007/p/3556941.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!