I have configured the access decision manager to check a request before being processed by the servlet the key line is:-
HttpServletRequest request = (HttpServletRequest) RequestContextHolder.currentRequestAttributes().getRequest();
All good. However when the request is enctype="multipart/form-data"
how do I get hold of the MultipartHttpServletRequest
when RequestContextHolder.currentRequestAttributes().getRequest()
only returns HttpServletRequest
?
I am using spring 2.5.
MultipartHttpServletRequest
is n Spring-specific interface for handling multipart form submissions. The default implementation isDefaultMultipartHttpServletRequest
, which has a constructor that takes aHttpServletRequest
.So:
If you are using spring-mvc, make sure you put this line
in your app-config.xml.
This worked for me.
Have you tried casting to
MultipartHttpServletRequest
?Apart from having
you have to have
in your spring configuration file.
Here is nice tutorial on the same
http://techdive.in/spring/spring-file-upload
I don't think you can get DefaultMultipartHttpServletRequest from RequestContextHolder. DefaultMultipartHttpServletRequest really implements HttpServletRequest. But there're 2 request instances if you use CommonsMultipartResolver. One is DefaultMultipartHttpServletRequest instance, and another is HttpServletRequest instance. Actually I don't know how to get the first instance from RequestContextHolder. You can get the second instance from it.