I’m trying to validate the contents of some files through a web interface and use the response to enable / disable some other functionality … like a save button. I’ve got as far as the submit and file handling (stubbed) but I cant seem to get my response to work properly.
Problem : on response tries to make user download a file with the response contents. I want to just pass the response to the success function to be handled.
JS Function Code:
function validateCopybook() {
//submit values.
console.log("validating");
if (this.getForm().isValid()) {
this.getForm().submit({
url : 'batch/validateCopybook.json',
waitMsg : 'Validating...',
success : function(form, action) {
this.msg('Success', 'Processed file on the server');
}
});
}
}
Server side code :
public ModelAndView validateCopybook(HttpServletRequest request, HttpServletResponse response) throws Exception
{
// Check whether we're dealing with a multipart request
String contentHeader = request.getHeader("content-type");
boolean isMultipart = (contentHeader != null && contentHeader.indexOf("multipart/form-data") != -1);
if (isMultipart == false)
{
return Helper.errorResponse("not multipart");
}
else
{
DefaultMultipartHttpServletRequest reqM = (DefaultMultipartHttpServletRequest) request;
MultiValueMap<String, MultipartFile> fileMap = reqM.getMultiFileMap();
MultipartFile copyIn = fileMap.get("copy-path-in").get(0);
MultipartFile copyOut = fileMap.get("copy-path-out").get(0);
}
System.out.println(response.getContentType());
response.setContentType("application/json");
ModelAndView mav = Helper.successResponse("success");
return mav;
}
Response returned :
ModelAndView: reference to view with name 'json'; model is {model={data={"success":true,"info":"success","dataLength":0,"data":[]}}}
Any ideas ?
Ok I wasnt setting the response header correctly
wasnt enough.
Works correctly.