首页 > 编程语言 > 详细

SpringMVC乱码问题

时间:2020-07-09 19:15:11      阅读:70      评论:0      收藏:0      [点我收藏+]

一、问题描述

  controller响应给前端的数据中包含中文,前端解析所得显示结果出现乱码。

二、解决方法

1、无返回值

@RequestMapping("ajaxReq")
public void ajaxReq(HttpServletRequest req,HttpServletResponse resp) throws IOException{
    resp.setCharacterEncoding("utf-8");
    resp.setContentType("text/html;charset=utf-8");
    String username = req.getParameter("username");
    String password = req.getParameter("password");             
resp.getWriter().write(username+" : "+password); }

2、有返回值

@RequestMapping(value="ajaxReq",produces="text/html;charset=utf-8")
@ResponseBody
public String ajaxReq(HttpServletRequest req,HttpServletResponse resp) throws IOException{
    String username = req.getParameter("username");
    String password = req.getParameter("password");
    return username+" : "+password;
}

 

SpringMVC乱码问题

原文:https://www.cnblogs.com/wxinyi/p/13275193.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!