利用JSP交互式打印表格

来源:互联网 发布:淘宝美工专业名词 编辑:程序博客网 时间:2024/04/29 20:30

问题:在客户端输入要打印表格的行数rows和列数cols,然后经过服务端处理打印rows*cols的表格,打印数据为i*j。

html部分:文件名:input.html

<html><head><title>Hello</title></head><body><form action="input.jsp" method="post">     <table border="1" width="100%">        <tr>             <td>请输入表格要显示的行数:</td>         <td><input type="text" name="row"></td>        </tr>        <tr>             <td>请输入表格要显示的列数:</td>         <td><input type="text" name="col"></td>        </tr>        <tr>             <td>     <input type="submit" value="显示"> <input type="reset" value="重置"> </td>        </tr>     </table></form></body></html>


JSP部分:文件名:input.jsp

<html><head><title>JSP</title></head><body><%    int cols=0;int rows=0;try{rows=Integer.parseInt(request.getParameter("row"));    cols=Integer.parseInt(request.getParameter("col"));}catch(Exception e){}%><table border="1", width="100%"><%    for(int i=0;i<rows;i++)    {%><tr><%      for(int j=0;j<cols;j++)      {%>                <td bgcolor="green"><%=i*j%></td><%      }%></tr><%}%><table></body></html>


 

原创粉丝点击