Home  >  Q&A  >  body text

javascript - form submission, background entity class receiving escape problem

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中文网2675 days ago880

reply all(2)I'll reply

  • 某草草

    某草草2017-06-23 09:15:32

    Try adding @RequestBody in front of the entity parameters

    reply
    0
  • 滿天的星座

    滿天的星座2017-06-23 09:15:32

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

    reply
    0
  • Cancelreply