GRAILS URLMapping : "exclude" not working: href link for opening a file is returning 404 error from a gsp page

StackOverflow https://stackoverflow.com/questions/15648307

  •  29-03-2022
  •  | 
  •  

Question

This is a weird issue :

I have link on a gsp page which should open a pdf file named "fileInstruction.pdf" from a location "/appName/docs" where "appName" is the name of the application

the html on the gsp looks like :

   <div>
        <h6>File examples and instructions</h6>
        <a href="/appName/docs/fileInstruction.pdf" target="blank">File format instructions</a>
   </div>

But clicking the link seems looking for a controller and I am getting 404 error. The folder has the pdf file as I tried :

"file:///C:/applications/appName/docs/fileInstruction.pdf" opened up the doc on the browser.

Tried to exclude url mapping as:

 class UrlMappings {
   static excludes = ["/docs/*"]
    static mappings = {
           ....
     }
 }

Does not seem to work. I am using grails 2.0.1.

What am I doing wrong?

Was it helpful?

Solution

The root directory of your application isn't the root for URLs, web-app is. Move it to C:/applications/appName/web-app/docs/fileInstruction.pdf and remove the changes in UrlMappings.groovy since that has nothing to do with static resources, only controller-based requests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top