<a href="http://192.168.1.163/ProductList.do?pageSize=40&Keywords=马可波罗&OrderBy=sellcount0-string&IsAsc=false&page=1">40</a>
点击进入后台后,Keywords参数接收的乱码,
String strKeyword = request.getParameter("Keywords");
strKeyword乱码的值是:?í???¨??
这个该怎么处理?a链接默认的是get提交 即时外面有个form表单是post
我也遇到过这样的问题 我是点击下一页的时候需要传中文 行不通 我就换了这个方法:
<form id="form" action="ArticleServlet?action=SearchNews&page=${page}" method="post">
<input name="key" id="key" type="hidden" value="马可波罗" />
<div id="MianBtNr" >
<a href="javascript:document:form.action='ArticleServlet?action=SearchNews';form.submit();"><img src=../images/page_top.gif border=0 align=absmiddle></a>
<c:if test="${page>1}">
<a href="javascript:document:form.action='ArticleServlet?action=SearchNews&page=${page-1}';form.submit();"><img src=../images/page_pv.gif border=0 align=absmiddle /></a>
</c:if>
<c:if test="${page<allpage}">
<a href="javascript:document:form.action='ArticleServlet?action=SearchNews&page=${page+1}';form.submit();" ><img src=../images/page_next.gif border=0 align=absmiddle></a>
</c:if>
<a href="javascript:document:form.action='ArticleServlet?action=SearchNews&page=${allpage}';form.submit();"><img src=../images/page_end.gif border=0 align=absmiddle></a>
共${allpage}页 当前第${page}页
</div>
</form>
把Keywords参数在前台用JS编码一下encodeURI!
a标签的href改为:href="javascript: functionName()"
JS代码:
function functionName(){
var d = "马可波罗";
var url = "http://192.168.1.163/ProductList.do?pageSize=40&Keywords="+encodeURI(d)+"&OrderBy=sellcount0-string&IsAsc=false&page=1";
window.location.href = url ;
}
后台:
//后台action或者servlet这样转码获取String s=new String(s.getBytes("GBK"),"UTF-8");
String Name=new String(URLDecoder.decode(request.getParameter("name"),"utf-8"));[/color]
这个方法很好
只有在极其特殊的情况下不会成功接收参数时进行转码String s=new String(s.getBytes("GBK"),"UTF-8");keyword=encodeURI('马可波罗') 试试在Web容器的server.xml文件中找到下面的节点、加上编码 URIEncoding="UTF-8"
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>抱歉:request.getParameter("name")
改为:request.getParameter("Keywords")
LZ祝你好运!