简体   繁体   中英

Weird Filter behavior

I have created a folder named 'content' under grails-app/view and serve all gsp files from there which does not require a controller action.

In order to serve this view, I had added a UrlMapping "/content/$view"(controller:"content"). This enables me to call /my-app/content/staticGSP directly without an actual ContentController. This is working fine for some time without any issues.

Today, I wanted to add a filter which would redirect to a view under content folder directly. I added a before closure in MYFilter.

  all(controller: "*") { 
       before = { 
             if(onSomeCond){ 
                 redirect(controller: 'content', action: 'seamless') 
                 return false 
             } 
            return true 
        } 
   } 

This filter works fine if I try a Url http://localhost:8080/my-app/home/index . Here I have a HomeController in my app. But, if I try http://localhost:8080/my-app/content/anotherview , then Filter just responds with a 404. I am not able to figure out why this is.

Any insight would be really helpful.

Thanks, Abhijith

Apparently http://localhost:8080/my-app/content/anotherview matches the url mapping "/content/$view"(controller:"content") and you do not have the view anotherview in static folder. anotherview is inside content folder. Hence, 404.

Is the name of the folder you added for static content is content or static ? Your question says static

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM