---
title: "JSP中文传参的乱码问题"
author: "Function"
date: "2011-12-26T10:19:21Z"
tags: []
slug: "jsp"
draft: false
lastmod: "2011-12-26T10:19:21Z"
id: 1326164
url: "https://milker.iteye.com/blog/1326164"
---

Tomcat的默认编码方式为 ISO-8859-1
所以中文参数都会以 ISO-8859-1 这种编码方式传到后台
例如：
传参方式：<a href="001.jsp?name=鞋子">goto</a>
后台获取：String name = request.getParameter("name");

这里的“name”为ISO-8859-1编码的“鞋子”
可是jsp页面的编码则为UTF-8，所以显示为乱码

用String转换 ：
String str = new String(name.getBytes("ISO-8859-1"),"UTF-8");
//“UTF-8”则为jsp页面的实际编码
//此处的str显示为“鞋子”