Chinese Messy Code of String

It's very strange that I found the messy code.I 've never seen this before.

this is the java code:

    /**
     * list
     * 
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list(Long adminId, String operation, Date beginDate,
            Date endDate, Pageable pageable, ModelMap model)
    {
        if (null == endDate)
        {
            endDate = new Date();
        }

        //query 30day before by default
        if (null == beginDate)
        {
            beginDate = DateUtils.addDays(endDate, -30);
        }
        List<LogConfig> logConfigs = logConfigService.getAll();
        List<Admin> admins = adminService.findAll();
        model.addAttribute("admins", admins);
        model.addAttribute("logConfigs", logConfigs);
        model.addAttribute("adminId", adminId);
        model.addAttribute("page", logService.findPage(adminId, operation,
                beginDate, endDate, pageable));
        model.addAttribute("operation", operation);
        model.addAttribute("beginDate", beginDate);
        model.addAttribute("endDate", endDate);
        return "/admin/log/list";
    }

And the String parameter "operation" was always messy code. 

I thought it was the matter of FreeMarker. If the front end code gave a String as a object.so background program would got a address of object.

but that is wrong.It is just different with the messy code.

Finally I added this two lines code:

        if (operation != null)
        {
            operation = (new String(operation.getBytes("ISO-8859-1"), "utf-8"))
                    .trim();
        }

that's ok.

but that's not the best way.

tomcat's encoding setting is the key of the problem.

 

 

posted on 2015-11-04 12:07  J·Marcus  阅读(721)  评论(0)    收藏  举报

导航