2 ArrayList < OrderList > list = (ArrayList)request.getAttribute( " list " );
3
4 for ( int i = 0 ;i < list.size();i ++ ) {
5 OrderList order = list.get(i);
6
7 out.print( " <tr> " );
8 out.print( " <td class=tablebody2 valign=middle align=center width=\ " \ " > " );
9 out.print( " <a href=\ " GetOrderInformation.jsp\ " > " );
10 out.print(i + 1 );
11 out.print( " </a> " );
12 out.print( " </td> " );
13
14 out.print( " <td class=tablebody2 valign=middle align=center width=\ " \ " > " );
15 out.print(order.getId());
16 out.print( " </td> " );
17
18 out.print( " <td class=tablebody2 valign=middle align=center width=\ " \ " > " );
19 out.print(order.getCount() * order.getPay());
20 out.print( " </td> " );
21
22 out.print( " <td class=tablebody2 valign=middle align=center width=\ " \ " > " );
23 if (order.getState() == 1 ){
24 out.print( " 已经确认 " ); }
25 else {
26 out.print( " 等待确认 " );
27 }
28 out.print( " </td> " );
29
30 int a = i;
31
32 out.print( " <td class=tablebody2 valign=middle align=center width=\ " \ " > " );
33
34 out.println( " <a href=\ " GetDataForOrderList.jsp ? dd = " + a + " \ " >明细 </a> " );
35
36 out.print( " </td> " );
37
38 out.print( " </tr> " );
39
40
41 }
42 %>
今天对于页面间传递参数的问题忙了我一个中午,原本我是想在34行添加一超链接实现给GetDataForOrderList.jsp页面传递i值,参考了网上很多的知识,都不能成功。
一开始得知 :<a href="GetDataForOrderList.jsp?id=<% = a%>">明细 </a> 是可以实现,不过如果我是用out.println()方法来表示jsp页面,如果按照上面那样写的话,提示出错,是jsp页面语法错误,我尝试了很多方法,最后终于在一位高人的问题上找到了答案。
代码如下:
country=rs.getString(1);//获取ResultSet返回的国家名,证实可以获取。
out.println(" <td>"+" <a href=\"country.jsp?country=<%=country%>\">"+rs.getObject(1)+" </a>"+" </td>");
由于是在网页中直接使用程序码片段,上述句子使用了转义字符。但传过去的country总是NULL
解决办法是用javascript取该组件在表单中的值
var a=document.form.text.value
然后用 window.location="nextPage.html?aa="+a 而不能用在页面中的变量的名字做传递参数
即window.location="nextPage.html?aa= <%=变量名%>"
因为变量为空的话 传过去就是个NULL的字符串
out.println(" <td>"+" <a href=\"country.jsp?country=" + country + "\">" + country + " </a>"+" </td>");
最后我参考了他最后的一段代码,终于成功了。希望对大家有帮助。