我要在jsp页面上获取url中的参数,参数中有中文会出现乱码

而且我试过new String(province.getBytes("ISO-8859-1"), "utf-8"),这个不行,有没有人能给出详细的解决方案,网上大多数方法都不可行

你需要保持jsp页面和Servlet类中的编码一致。
jsp页面:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body></body>
</html>
Servlet类中:
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
{
request.setCharacterEncoding("UTF-8") ;
.....
}
温馨提示:答案为网友推荐,仅供参考
相似回答