使用spring和getjson编码重音错误

时间:2014-03-01 15:28:43

标签: jquery json spring-mvc

我想在变量mois中发送参数:“Février”,问题是当我发送包含é的重音的参数时,我通过@ResponseBody在类java中得到其他值:Février 我的网址是: http://othman-pc.com:8080/COSUMAR_WebAdmin/moisTest.html?mois = FEVRIER

问题是控制台java中的问题:System.out.println("Mois :"+ mois);

我得到:

Mois :Février

Getjson:

$.getJSON("moisTest.html", {mois: $(this).val()}, function(j) { if (j === false) { alert("good")     });

Spring @ResponseBody

@RequestMapping(value = "/moisTest.html",method = RequestMethod.GET)
  public @ResponseBody String moisTest(@RequestParam(value ="mois") String mois){
             System.out.println("Mois :"+ mois);

            return "false";}

我的JSP:

<%@ page  contentType="text/html; charset=ISO-8859-1" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib  uri="http://www.springframework.org/tags/form" prefix="form" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 

标题雕像:

Request URL:http://localhost:8080/COSUMAR_WebAdmin/moisTest.html?mois=F%C3%A9vrier
Request Method:GET
Status Code:200 OK
Request Headersview source
Accept:application/json, text/javascript, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=0.2
Cache-Control:max-age=0
Connection:keep-alive
Content-Type:application/x-www-form-urlencoded
Cookie:JSESSIONID=zMFHDOspJtUYA+Eg4hidb+C1.undefined; ASP.NET_SessionId=ohyxckjs40vkg121wnnvygwn; fcspersistslider2=1; submenuheader=0c; PHPSESSID=vak58e1nha6mg51prp4ke0l3f3; JSESSIONID=29a2a59a435d5e9fe335568f602d; treeForm_tree-hi=treeForm:tree:resources:JDBC:connectionPoolResources:evpsPool
Host:localhost:8080
Referer:http://localhost:8080/COSUMAR_WebAdmin/upload.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36
X-Requested-With:XMLHttpRequest
Query String Parametersview sourceview URL encoded
mois:Février
Response Headersview source
Cache-Control:no-cache
Cache-Control:no-store
Content-Length:5
Content-Type:application/json
Date:Sat, 01 Mar 2014 15:08:05 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Pragma:no-cache
Server:Apache-Coyote/1.1    

1 个答案:

答案 0 :(得分:2)

在tomcat上运行的应用程序是常见问题。要解决此开放式server.xml tomcat配置,请在您的端口中找到<Connector>标记(例如8080)并添加以下内容:URIEncoding="UTF-8"

服务器配置可以在项目浏览器的服务器文件夹或“Servers”文件夹中找到(如果使用eclipse)

server.xml location