利用url传多个参数
刚开始接触jsp,比较偏向于用button标签的onclick方法进行页面的跳转。但是关于页面跳转的各种问题真是叫人头大,以下记录,仅仅为自己以后查看。
Qone 用url传参的时候遇到中文怎么办
编码再解码:传输时用encodeURI进行编码,获取参数时URLEncoder.encode进行解码;
页面1:
function sub(){ var content1 = document.getElementById("tn"); var content2 = document.getElementById("ln"); alert(content1.value); alert(content2.value); window.location.href="value.jsp?"+"tn="+encodeURI(content1.value)+"&ln="+encodeURI(content2.value); }
页面2:
在定义get方法时,进行解码
public String get_url_Name() throws UnsupportedEncodingException { String encodedname = URLEncoder.encode(name, "UTF-8"); return encodedname; }
Qtwo:url传输多个参数时到底该怎么写
href="下一页面.jsp?"+参数+“&参数名”+参数值
加号不能少,不然页面跳转就会失败
ps:这种明传址的方法不安全,但是暂时不会别的方法,将就用吧,有时间回看。