写jsp页面时遇到的值传递问题

值传递问题

    int id;
    int rootid;
    try{
        id = Integer.parseInt(idStr);//这里是从上一个页面传过来的值
        rootid = Integer.parseInt(rootidStr);//这里是从上一个页面传过来的值
    } catch (NumberFormatException e){
        out.println("Error NumberFormat");//catch Exception的处理
        return;
    }

然后我在下面的代码中,把这两个值(id 和 rootid)在链接的后面,想通过类似于

<a href="replyOk.jsp?id=<%=id%>&rootid=<%rootid%>" />

这样的方式传递的下一个页面。

结果下一个页面收到的参数为空。

一直搞不懂为什么,不过只要在声明id和rootid的时候,像下面这样

    int id = 0;
    int rootid = 0;

这样就可以正常传递过去了,搞不懂为什么,以后复习的时候再来解决。


2017/8/23 修改

不对不对,还是传不过去,贴上全部代码

    <%
    int id;
    int rootid;
    try{
        id = Integer.parseInt(idStr);//这里是从上一个页面传过来的值
        rootid = Integer.parseInt(rootidStr);//这里是从上一个页面传过来的值
    } catch (NumberFormatException e){
        out.println("Error NumberFormat");//catch Exception的处理
        return;
    %>
    <form name=reply action="replyOK.jsp?pid=<%=id %>&rootid=<%=rootid %>" method="get">
//方式一

想通方式一传过去下一个页面,发现下一个页面收到的是空值(null).

    <form name=reply action="replyOK.jsp" method="get">
    <input type="hidden" name="pid" value="<%=id %>">
    <input type="hidden" name="rootid" value="<%=rootid %>">
    //方式二

方式二没问题,觉得好奇怪

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值