Hi everyone,
I've looked everywhere for a nice concise solution to the problem of page refreshes after submitting a form to upload a file using Spring.
I am able to upload files using a custom Ajax solution with a Controller backend.
My form definition looks like so, with my custom JSON parameters as input:
My handleRequestInternal in my Controller looks like so:Code:<form method='post' id='ajax_upload_form' action="rules_upload.web" enctype="multipart/form-data" onsubmit="Portal.doAjaxUpload({'formElement':'ajax_upload_form', 'statusElement':'statusdiv', 'updateElement':'testdiv'}, {'beanId':'fileUploadBean', 'eventId':'checkUploadStatus', 'progressElement':'trash'})"> Rules Document: <input type="file" name="rulesfile"/> <input type="submit" name="submit" value="Upload"/> </form>
So, the handleFileUpload does all the commons upload stuff, and I end up with a nice file on my server. However, I get a page refresh when using this method, and the new page is blank. Is there any way of getting Spring to just stay on the same page and let my Ajax stuff update the correct portions of the page? I have some progress monitoring Ajax code going on which also seems to work, but obviously the page refresh is the big problem.Code:protected ModelAndView handleRequestInternal( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception { URL localFileLocation = null; try { // parse the file localFileLocation = FileUploader.handleFileUpload(httpServletRequest); } catch (IOException ioe) { Map<String, String> messageMap = new HashMap<String, String>(); messageMap.put("message", "There was a problem uploading the file - " + ioe.getMessage()); return new ModelAndView("upload_fail.jsp", messageMap); } return null; }
I don't want to use DWR, Spring Javascript or Web Flow (with the number of potential updates made to our pages, fragment-based page replacements aren't feasible), and I couldn't get XT to work with its very complicated set up.
Any suggestions? I'm happy to post up additional code.
Cheers
Rob


Reply With Quote
