js 中文传参乱码

 js中文传参需要对中文转码:

js代码:

function submitForm()
{
 var hnbID = $.trim($("#hnbID").val());
 var alarmID = $.trim($("#alarmID").val());
 var alarmType = encodeURIComponent(encodeURIComponent($.trim($("#alarmType").val())));
 var perceivedSeverity = $.trim($("#perceivedSeverity").val());
 var probableCause = encodeURIComponent(encodeURIComponent($.trim($("#probableCause").val())));
 var alarmState = $.trim($("#alarmState").val());
 var startAlarmRaisedTime = $.trim($("#startAlarmRaisedTime").val());
 var endAlarmRaisedTime = $.trim($("#endAlarmRaisedTime").val());
 //访问地址
 url = "getAllActiveInfo?hnbID=" + hnbID + "&alarmID=" + alarmID + "&alarmType=" + alarmType + "&perceivedSeverity="
   + perceivedSeverity + "&probableCause=" + probableCause + "&alarmState=" + alarmState
   + "&startAlarmRaisedTime=" + startAlarmRaisedTime + "&endAlarmRaisedTime=" + endAlarmRaisedTime;
 document.dataList.action = url;
 document.dataList.submit();
}

 

红色部分是转码代码,转码需要转两遍。

 

java后台接收代码:

 @RequestMapping("/getAllHistoryInfo")
    public ModelAndView getAllHistoryInfo(HttpServletRequest request, HttpServletResponse response,
        HistoryAlarmInfo history, PageInfo page)
    {
        try
        {
            //从request范围内获取告警类型和告警原因,如果获取的属性不为空则进行转码并放到类对象中
            if (null != request.getParameter("alarmType") && !"".equals(request.getParameter("alarmType")))
            {
                String alarmType = URLDecoder.decode(request.getParameter("alarmType"), "UTF-8");
                history.setAlarmType(alarmType);
            }
            if (null != request.getParameter("probableCause") && !"".equals(request.getParameter("probableCause")))
            {
                String probableCause = URLDecoder.decode(request.getParameter("probableCause"), "UTF-8");
                history.setProbableCause(probableCause);
            }
                        
            //获取所有告警配置信息和基站信息
            List<AlarmInfoConfig> alarmList = forService.getAlarmInfo();
            List<HnbInfo> hnbList = hnbService.getHnbList();
           
            List<HistoryAlarmInfo> historyList = null;
            
             if (null != roleBank && null != history)
            {
                   historyList = historyService.getAllHistoryInfo(history, page); 
             }
           
            //把对象放到request范围
            request.setAttribute("historyList", historyList);
            request.setAttribute("history", history);
            request.setAttribute("hnbList", hnbList);
            request.setAttribute("alarmList", alarmList);
            request.setAttribute("page", page);
        }
        catch (Exception e)
        {
            // TODO: handle exception
        }
        return new ModelAndView("warning/history_List");
    }

红色部分是后台接收解码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值