码迷,mamicode.com
首页 > 编程语言 > 详细

javaweb 解决jsp中${}传递中文值到后端以及get请求中文乱码的问题

时间:2018-11-19 17:29:30      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:config   temp   pos   oms   prim   ted   bytes   response   编码   

 

首先,不要用get传中文,我试了一些方法发现不行,所以果断决定用post传参,

这里用 encodeURI 进行一次编码传入后端

注意:${tplname} 要加 ‘

        $.ajax({
            url: ‘/RM/controller/json/ConfigTemplateCustomController/fetchTemplateCustomContentsByTplName/tplname/post‘,
            type: ‘POST‘,
            async: false,
            data:{
              ‘tplname‘:encodeURI(‘${tplname}‘)
            },
            success:

 

这样解码后再 getBytes 就解决了

    @RequestMapping(value = "controller/json/ConfigTemplateCustomController/fetchTemplateCustomContentsByTplName/tplname/post", method = RequestMethod.POST)
    @ResponseBody
    public BaseResult fetchTemplateCustomContentsByTplName(String tplname) throws UnsupportedEncodingException {
        tplname = URLDecoder.decode(tplname,"utf-8");
        tplname =  new String(tplname.getBytes("ISO-8859-1"),"UTF-8");
        return ResultUtil.success().add("TemplateCustom", configTemplateCustomService.selectByPrimaryKey(tplname));
    }

 

javaweb 解决jsp中${}传递中文值到后端以及get请求中文乱码的问题

标签:config   temp   pos   oms   prim   ted   bytes   response   编码   

原文地址:https://www.cnblogs.com/kinome/p/9983735.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!