如何在不使用Ajax调用的情况下将JSON.stringify数据从JSP发送到Spring Controller

时间:2018-10-04 15:02:05

标签: javascript json spring-mvc

我正在尝试将JSON.stringify数据从jsp发送到我的spring控制器。

这是我的jsp代码。

for (var i = 0; i < JSONObj.length; i++) {

                                            var remarkString = $(
                                                    "#eduRemark" + k).val();
                                            var scoreNum = $("#eduScore" + k)
                                                    .val();

                                            var objectInfo = {
                                                "iqrQuestionRemark" : remarkString,
                                                "iqrQuestionScore" : scoreNum
                                            };
                                            sample.push(objectInfo);

                                            k++;
                                        }

                                        var ArrayData = JSON.stringify(sample);

在控制器即时消息接收数据如下

@RequestMapping(value={VspCommonConstants.INTERVIEW_PANEL_MANAGER_URL+"/submitAssessmentform"}, method = RequestMethod.POST)
    public String submitAssessmentform(@RequestBody String ArrayData,@RequestParam("existFlag") boolean existFlag,@RequestParam("questionMasterid") String questionMasterid
            ,@RequestParam("appid") String appid,HttpServletRequest request,Model model) throws JsonParseException, JsonMappingException, IOException
    {

        UserInfo uInfo = (UserInfo) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        List<InterviewQuestionResult> existQuestionResult = interviewQuestionResultService.getRecordByAppIdAndUmId(Long.parseLong(appid),new Long(uInfo.getId()));

        if(existQuestionResult.size() == 0){
            existFlag = false;
        }else{
            existFlag = true;
        }

        int QuestionMasterid = Integer.parseInt(questionMasterid); 
        int Appid = Integer.parseInt(appid);
        ObjectMapper mapper = new ObjectMapper();
        System.out.println("Json converted Data:"+ArrayData);
    /*  mapper.setSerializationInclusion(Include.NON_NULL);
        mapper.setSerializationInclusion(Include.NON_EMPTY);*/
        InterviewQuestionResult[] actualData = mapper.readValue(ArrayData, InterviewQuestionResult[].class);
        System.out.println("Json converted Data:"+actualData.toString());

当我从jsp发送数据时,它看起来像

Arraydata : [{"iqrQuestionRemark":"aaa","iqrQuestionScore":"2"},{"iqrQuestionRemark":"bbb","iqrQuestionScore":"1"},{"iqrQuestionRemark":"ccc","iqrQuestionScore":"3"}]

但是在控制器处,我正在接收ArrayData中的数据,如下所示

nameOfStud=CHAKRESHWARA+K&saveFlag=&studid=2018-10-04+20%3A29%3A32&studid=229359&appid=293560&questionMasterid=&existFlag=true

出于某种原因,我无法为此使用ajax调用。请告诉我如何仅通过表单提交来实现。预先感谢

0 个答案:

没有答案