Java / Spring / Angular.js passing the file path to the controller


I am trying to return a file from the server based on the path that I pass in through the dirFile parameter. But, I can't get the dirFile parameter to the controller.

Here is my controller on the server:

@RequestMapping(value="/test/getFile/{dirFile}", method = RequestMethod.GET)
public void doDownload(HttpServletRequest request, HttpServletResponse response,
@PathVariable String dirFile) throws IOException { ...returns file }

Here is how I am currently making the call:

<a ng-href="/Web/test/getFile/{{encodeFileURL(}}">Click here to download file</a>

The parameter populates fine and produces the following URL:


Without the parameter the controller does it's job and returns a file that I have hardcoded, but I want to return the file that is passed in. I can't seem to get the controller to accept the parameter for the file path though, it always returns something like a 400 Bad Request Error. I have tried a bunch of different variations of spring handlers but can't find something that works. What am I doing wrong?

Update: It's something with the encoding. I think it's encoded with UTF-8 and the tomcat is using something else. I'm going to try to pass as JSON or something instead.

It is probably because by default Spring treats urls with extension as file names. Try setting the property useSuffixPatternMatch of handlerMapping to false.

If you use Java Configuration:

   public RequestMappingHandlerMapping requestMappingHandlerMapping() {
        RequestMappingHandlerMapping handlerMapping = super.requestMappingHandlerMapping();