Home >Web Front-end >HTML Tutorial >Glassfish在SpringMVC服务端接收请求时字符出现乱码的解决办法_html/css_WEB-ITnose

Glassfish在SpringMVC服务端接收请求时字符出现乱码的解决办法_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:23:521491browse

环境描述

前端:jsp

后端:SpringMVC Controller

 

尽管jsp页面已设置了pageEncoding:

<%@page contentType="text/html" pageEncoding="UTF-8"%>

然后在控制器中,读取到的对应参数如果含有中文,则出现乱码,例如:

public ModelAndView search(@RequestParam("keyword") String keyword) {    //keyword乱码    }

 

解决办法

新建xml文件名为“glassfish-web”,添加以下代码:

<?xml version="1.0" encoding="UTF-8"?><glassfish-web-app>    <parameter-encoding default-charset="UTF-8" /></glassfish-web-app>

保存至 /WEB-INF 目录下即可。

 

参考链接:http://stackoverflow.com/questions/25870583/glassfish-spring-not-correctly-decoding-utf-8-in-post

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn