---
title: "页面传递中文乱码处理"
author: "屌丝学Java"
date: "2017-10-18T17:57:48Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2017-10-18T17:57:48Z"
id: 2396855
url: "https://451640893.iteye.com/blog/2396855"
---

转来的，好用

```java
传中文查询乱码问题 则需要对要传的参数进行二次编码
例如  window.location.href ="/xx.jsp?name="+name+""; 
这样子则会乱码
改成
window.location.href ="/xx.jsp?name="+  encodeURI(encodeURI(name))+""; 

在接受的jsp页面 或者是controller 中进行解码
String name = java.net.URLDecoder.decode(request.getParameter("name"), "utf-8");

这样子即解决在用 window.location.href  传中文的乱码问题
```