js 与jsp传输变量

今天遇到 js与jsp传输变量的问题,先记录自己的解决方法:

      function search() {
                                var startDate = $('#startDate').val();
                                var endDate = $('#endDate').val();
                                var from = encodeURIComponent($('#from').val());                   //由于from传的一般都是中文,这里需要进行转码
                                var to = encodeURIComponent($('#to').val());
                                var count = $('#count').val();
                                var urlStr = '<%=jspName%>?startDate='startDate'&endDate='endDate'&action=query&action=query&from='from'&to='to'&count='count'';

                                window.location.href=urlStr;

       }

……

                   //通过input传输

                      <input name="from" type="hidden" value='<%=from%>' id='from'>                    //这里的初始值是第一次跳转时传进来的
                         <input name="to" type="hidden" value='<%=to%>' id='to'>
                         <input name="count" type="hidden" value='<%=sum%>' id='count'>

//在 window.location.href=urlStr; 跳转的页面中,通过request.getParameter()方法取得参数

        String from = request.getParameter("from");
        String to = request.getParameter("to");
        int sum = Integer.parseInt(request.getParameter("count"));


在网上也看到别的方法,下面就把相关链接贴在这里吧,做个笔记。


http://blog.sina.com.cn/s/blog_4745d1c10100nfv8.html

http://blog.csdn.net/qinweizhao/article/details/6683557


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值