今天遇到 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'';
}
……
//通过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