日期:2014-05-18 浏览次数:20681 次
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %> <!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=utf-8"> <title>无标题文档 </title> </head> <%int bb=0;%> <body> <form action="" name="myform"> <table width="780" border="0" cellspacing="1" cellpadding="0"> <tr> <td> <div align="center"> <span class="style2">Please choose the parameter of the period: Year of Period </span> <input type="text" name="t" value="2009"/> NO <select name="aa" onchange="myform.submit()"> <option value="" selected>please choose </option> <option value=1>1 </option> <option value=2>2 </option> </select> </div> </td> </tr> </table> </form> <% String cc = request.getParameter("aa"); if(cc!=null&&!cc.equals("")) bb=Integer.valueOf(cc).intValue();System.out.println(bb);%> <% for(int i=1;i <=bb;i++){%> <input type="text" name="a<%=i%>"> <% } %> </body> </html>
------解决方案--------------------
问题出在这:
bb=request.getParameter("aa");
1)request.getParameter返回的是个string,bb是int型。必须要转换。
2)第一次进入画面时 request.getParameter("aa")是null。需要特殊处理