Thanks to spring latest releases there is no need to implement any Controller classes and to use un-necessary XML tags floating in the project.
1)
JSP:
<form id="uploadForm" enctype="multipart/form-data" action="<c:url value='/importdata/upload.html' />" method="POST" >
<input type="file" id="file" name="file" size="100" maxlength="500" />
<input type="submit" id="uploadButton" value="Upload File" onclick="document.getElementById('uploadButton').disabled='true';try{document.getElementById('uploadForm').submit();}catch(Exception e){document.getElementById('uploadButton').disabled='true'}" />
....
</form>
Our jsp will infact remains the same and for submission it refers to the URL it wants to navigate.
2) Remove the previous declared xml configurations in the corresponding xml file.
3) Now Our Controller class will use the annotations.
@Controller
@RequestMapping(value = "/importdata/**")
public class DoImportController {
private ILookUpService lookupService;
String successView="/importdata/viewImportSpreadsheetSummary";
String formView="/importdata/viewImportSpreadsheet";
@Autowired
public DoImportController(ILookUpService lookupService) {
this.lookupService = lookupService;
}
@RequestMapping(value = "/upload.html", method = RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request,HttpServletResponse response,@RequestParam("utility") String utility,@RequestParam("file") MultipartFile file)
throws ServletException, IOException, Exception {
.......
return new ModelAndView(successView, "importResult", data);
}
...
}
No comments:
Post a Comment