zoukankan      html  css  js  c++  java
  • SpringMVC乱码问题

    一、问题描述

      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;
    }
  • 相关阅读:
    net core 3.1 依赖注入
    vue temeplete standard
    net core 3.1 Global
    vue Multiple selection
    c# mvc modelstate
    vue temeplete
    vue element pickdate combox input 排版
    c# 生成 验证码
    vue checkbox ajax
    js算法(2)
  • 原文地址:https://www.cnblogs.com/wxinyi/p/13275193.html
Copyright © 2011-2022 走看看