zoukankan      html  css  js  c++  java
  • IDEA部署Tomcat应用所有接口中文乱码

    解决问题的思路:

    1、分析比对http请求头,contentType等设置

    2、前段编码,后端解码,这个方式比较落麻烦,凡是有中文乱码的地方都要进行解决

    3、修改Tomcat的默认编码,tomcat8以下默认编码是"iso8859-1",tomcat8默认编码是“UTF-8”

    <Connector port="8080" protocol="HTTP/1.1"
                   URIEncoding="UTF-8" 
                   connectionTimeout="20000"
                   redirectPort="8443" />

    4、查看应用的web.xml默认编码是否是"UTF-8"以下是后端强制转码配置

    <filter>
            <filter-name>Set Character Encoding</filter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
            <init-param>
                <param-name>forceEncoding</param-name>
                <param-value>true</param-value><!-- 强制进行转码 -->
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>Set Character Encoding</filter-name>
            <url-pattern>/*</url-pattern>
            <dispatcher>REQUEST</dispatcher>
            <dispatcher>FORWARD</dispatcher>
        </filter-mapping>

     按照此种写法HttpServletRequest和HttpServletResponse在控制层是不可缺少的,否则有乱码

    /**数据透传下发记录*/
        @RequestMapping("sendTransparentinfoSendCmd")
        public Object sendTransparentinfoSendCmd(TransparentinfoSendlog transparentinfoSendlog,HttpServletResponse response,HttpServletRequest request){
            if(transparentinfoSendlog.getVehicleId()==null){
                // 未选择车辆
                return setReturnMap(false, HttpCode.NO_SELECT_VEHICLE.value());
            }
            String sim=terminalService.findMobileCodeByVehicleId(transparentinfoSendlog.getVehicleId()+"");
            if(sim==null||sim.equals("")){
                return setReturnMap(false, HttpCode.ORDER_SEND_NO_SIM.value());
            }
            if(transparentinfoSendlog.getEnterpriseId()==null){
                // 没有公司ID
                return setReturnMap(false, HttpCode.BAD_REQUEST_ENTERPRISE.value());
            }
    
            // 存储数据透传下发发送日志
            OrderInfo orderInfo=new OrderInfo();
            orderInfo.setId(com.cvnavi.util.WebUtil.getPK());
            User user = WebExecutionContext.getUser();
            orderInfo.setUserId(user.getId());//设置userId
            // 设置指令ID
            transparentinfoSendlog.setOrderId(orderInfo.getId());
            boolean flag=iTransparentinfoService.insertTransparentinfoSendlog(transparentinfoSendlog);
            if(!flag){
                return setReturnMap(false, HttpCode.BAD_REQUEST.value());//请求错误
            }
            // 发送指令到网关
            orderInfo=iOrderInfoService.sendTransparentinfoSendlogCmd(orderInfo,transparentinfoSendlog);
            if(orderInfo==null){
                return setReturnMap(false, HttpCode.BAD_REQUEST.value());//请求错误
            }
            if("0".equals(orderInfo.getStatus())){
                return setReturnMap(false, HttpCode.NO_VEHICLE_ONLINE.value());//车辆不在线
            }else if("-1".equals(orderInfo.getStatus())){
                return setReturnMap(false, HttpCode.ORDER_SEND_FAIL.value());//指令发送失败
            }
            return setReturnMap(true, HttpCode.OK.value());
        }
  • 相关阅读:
    Navicat
    Eclipse 代码质量管理插件
    oracle sql 逻辑处理
    view视图 | 索引
    LIKE模糊查询
    启动tomcat报找不到或无法加载主类
    oracle:decode
    oracle:case when then else end
    ssh 公共秘钥
    ip 和数字之间的转换
  • 原文地址:https://www.cnblogs.com/boonya/p/7880465.html
Copyright © 2011-2022 走看看