javascript - form submission, background entity class receiving escape problem
PHP中文网
PHP中文网 2017-06-23 09:13:32
0
2
949

Question: The front-end form is submitted with ajax, the data is validateForm.serializeArray(), and the back-end uses entity classes to receive parameters. The & symbol is escaped as &, but it is no problem to directly get the value from the request. How to solve the problem of entity classes? Escape problem of received parameters.

code show as below:

前台代码:

var formData = validateForm.serializeArray();

$.ajax({
    type: 'POST',
    cache: false,
    url: basepath + "/newProjectAdjustment/saveProjectAdjustmentInfo.do",
    data: formData,
    dataType: "json",
    async:false,
    success: function (result) {
        if (result.success) {
            saveFlag = true;
        } else {
            parent.$.messager.alert("提示", result.msg != "操作成功" ? result.msg : projMessage.get("C008"), "info");
        }
    },
    error: function (result) {
        parent.$.messager.alert("提示", projMessage.get("C008"), "info");
    }
});
return saveFlag;
后端代码:
@RequestMapping(value = "saveProjectAdjustmentInfo.do", method = RequestMethod.POST)
@ResponseBody
public AjaxJson saveProjectAdjustmentInfo(HttpServletRequest request, ProjectAdjustmentDTO projectAdjustmentInfo) throws InvocationTargetException, IllegalAccessException {
    Map params = FormFormatterUtil.formatFrom2Map(request);
 
    AjaxJson result = new AjaxJson();
   
    return result;
}

Debug:
这是实体类中接收的参数:

这是request种接收的参数:

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
某草草

Try adding @RequestBody in front of the entity parameters

滿天的星座

Use StringEscapeUtils.unescapeHtml4() in the set method of the entity class to reverse escape.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template