0
点赞
收藏
分享

微信扫一扫

利用JSP交互式打印表格


问题:在客户端输入要打印表格的行数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>

 

举报

相关推荐

0 条评论