
客户端浏览器向服务器提交中文参数的时候,分为两种情况:点击href链接和提交表单。
1、点击href链接 http://127.0.0.1/Test/test.jsp?name=黄河
虽然在web.xml中进行配置的时候,使用了过滤器对编码进行转换,但是过滤器在这里并不起作用。这就需要在JSP页面中进行转码。
<a href='http://127.0.0.1/Test/test.jsp?name=<%= URLEncoder.encode("黄河","gb2312")%>' >链接</a>
在服务器端进行接收的时候,需要对字符进行解码
String str = request.getParameter("name")
String name = new String(str.getBytes("iso-8859-1"),"gb2312")
这样,System.out.println(name)输出的就是中文字符"黄河"
2、提交表单 对于文本框类型的表单组件提交中文参数的时候,使用web.xml中配置的过滤器就可以了。
注意,form表单的提交方式必须是post方式,如果是get方式的话,即使经过了过滤器依然是乱码
<input type="text" name="name">中国</input>
<select name="name2"><option value="中国" select="select">中国</option>
</select>
您好,您需要的只是一个明传址,这种方式会把参数以明文的方式传过去,这样是不安全的。虽然在技术上是可以实现的。<form action="#">
<input type="text" name="d_id" id="d_id"/><input type="text" name="d_name" id="d_name"/>
<input id="btn" type="button" value="sublimt"/>
</form>
<script>
document.getElementById('btn').onclick = function(){
var d = document.getElementById('d_id').value
var name = document.getElementById('d_name').value
location.href = 'a.asp?d_id=' + d + '&d_name=' + name
}
</script>
========================================
<form action="a.asp" method="post" onsubmit="return send()">
<input type="text" name="d_id" id="d_id"/><input type="text" name="d_name" id="d_name"/>
<input id="btn" type="submit" value="sublimt"/>
</form>
<script>
function send(){
if(document.getElementById('d_id').value.length <1){
alert('请正确输入!')
return false
}
return true
}
</script>
$("#all_cities dd a").click(function(){$(this).attr("href",$(this).attr("href")+"&url=sigecity")
})
这里只对<dl id="all_cities">这个标签下的<dd>中的所有a标签加属性,如果你想扩大范围,可以修改上面的选择器,如果想改变添加的参数名和参数值,在click()方法中进行相应修改..
jquery很简单很好学,建议你有空看下相应的例子和API,自己拿这个来做开发比在百度问别人好的多
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)