Danilo M.
Danilo M.

Reputation: 1592

Spring missing the extension file

I am developing an application using Spring MVC, and Extjs and I have a problem, I need to pass a file path to my controller, which going to delete the image with the path. However in my view the path is correct, but when the request arrive in controller the path is without extension.

View : notepad-icon.png

Controller: notepad-icon

@RequestMapping (value = "/delete/{file}", method = RequestMethod.DELETE)
public ModelAndView delete(@PathVariable String file){
    ModelAndView view = new ModelAndView(VIEW);
    service.delete(file);
    view.addObject("success", Boolean.TRUE);
    return view;
}

Can anyone provide me a insight, please ??

Upvotes: 2

Views: 2834

Answers (2)

Ranuka
Ranuka

Reputation: 773

Just add {file:.+} to the RequestMapping.

@RequestMapping (value = "/delete/{file:.+}", method = RequestMethod.DELETE)

Upvotes: 1

Biju Kunjummen
Biju Kunjummen

Reputation: 49915

If it is a simple extension can I recommend doing this:

@RequestMapping (value = "/delete/{file}.{ext}", method = RequestMethod.DELETE)
public ModelAndView delete(@PathVariable("file") String file, @PathVariable("ext") String ext){
    ModelAndView view = new ModelAndView(VIEW);
    service.delete(file + "." + ext);
    view.addObject("success", Boolean.TRUE);
    return view;
}

Another way to do this will be a little roundabout - this will be by setting the useSuffixPatternMatch flag in RequestMappingHandlerMapping to false, which should give you the entire filename, however setting the flag is a little difficult.

Upvotes: 2

Related Questions