Hi,
I'm a Spring Newbie and my first task is to upload a file from a web form, validate the values in the file and then put these data into a database. So, the most things are working already, but I have a problem with resolving the filename in my validation class.
I know there is the possibility to resolve the filename in the Controller like this:
FileUploadController:
but i need the filename in my Validator and the Validator is called before the Controller gets in action.Code:protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws ServletException, IOException { MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; CommonsMultipartFile fileinp = (CommonsMultipartFile) multipartRequest.getFile("file"); String filename = fileinp.getOriginalFilename(); [...]
[...]-servlet.xml:
QueryValidator.java:Code:<bean id="fileUploadController" class="[...].FileUploadController"> <property name="sessionForm"><value>true</value></property> <property name="commandName"><value>fileUploadBean</value></property> <property name="commandClass"><value>[...].FileUploadBean</value></property> <property name="formView"><value>upload</value></property> <property name="validator"> <ref bean="queryValidator"/> </property> <property name="queryManager"> <ref bean="queryMan"/> </property> </bean>
Thanks for any help,Code:public void validate(Object obj, Errors errors) { // no request... -> no getOriginalFilename() ??? [...]
4had


Reply With Quote