web 项目中a标签传值(中文)到后台的乱码问题
当点击下一页出现乱码问题:
因为title向Servlet传输的是中文,所以点击下一页会出现乱码问题
解决方法:
JSP:
<script type="text/javascript">
var href=$("#redirectUrl").attr("href");
href = encodeURI(href);
$("#redirectUrl").attr("href",href);
</script>
<a id="redirectUrl" href="/admin/ArticleServlet pageNum=${pageBean.pageNum+1}&itemid=${itemid}&title=${title}">下一页</a>
Servlet:
title = new String(title.getBytes("ISO-8859-1"),"UTF-8")
JSP页面编码设置为UTF-8
GET提交方式乱码问题:
String name = request.getParameter("name ");
name= new String(name.getBytes("ISO8859-1"), "UTF-8");
POST提交方式乱码问题:
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");