关于JSP页面间传递变量的讨论

 
  
1 <%
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=&lt;%=country%&gt;\">"+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>");

 

 

   最后我参考了他最后的一段代码,终于成功了。希望对大家有帮助。

转载于:https://www.cnblogs.com/SCAU_que/articles/1783021.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值