Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7714149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:03:23+00:00 2026-06-01T02:03:23+00:00

I have a filter: class MyFilters { def filters = { before = {

  • 0

I have a filter:

class MyFilters {
    def filters = {
        before = {
            render(view: "/test")
            return false
        }
    }
}

This works great on pages where I’m using a controller to handle the request, showing the contents of test.gsp instead of the page I requested. However, when I try to access a page that maps directly to a GSP file, I get a 404 error.

Changing the render to simply render "test" produces the same results, as does commenting it out and just leaving the return false.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:03:24+00:00Added an answer on June 1, 2026 at 2:03 am

    Grails is a MVC framework. If you want to map an URL directly to a GSP (without redirection through a controller and action) you need to explain this to grails within your UrlMappings.groovy. There you can define your “shortcuts”. E.g.:

    static mappings = {
        "/$viewName"(view:"/index") {
            constraints {
                viewName([some constraints])
            }
        }
    }
    

    Which will render views/index.gsp without going through a controller. If you do NOT define a controller mapping (or at least a view mapping) for those URLs, you canNOT use grails filters:

    If you really want to intercept ALL requests, you can add a servlet filter to your grails application like this:

    import javax.servlet.*
    
    import org.springframework.web.context.support.WebApplicationContextUtils;
    
    class TestFilter implements Filter {
    
        def applicationContext
    
        void init(FilterConfig config) throws ServletException {
            applicationContext = WebApplicationContextUtils.getWebApplicationContext(config.servletContext)
        }
    
        void destroy() {
        }
    
        void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    
            System.out.println("this filter has been called");
        }
    }
    

    In here you can do your redirections or renderings based on the applicationcontext and the current request.

    You need to add this filter to your web.xml. On how to do this, have a look at: How do i use a servlet in my grails app?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a filter that looks like this: <filter> <filter-name>TestFilter</filter-name> <filter-class>org.TestFilter</filter-class> <init-param> <param-name>timeout</param-name> <param-value>30</param-value>
I have the class filter.cs with this attributes: public virtual int Id { get;
I have a Filter Method in my User Class, that takes in a list
I have a checkstyle suppression filter setup (e.g. ignore magic numbers in unit test
I have a filter and parameters in web.xml web.xml is like this: <filter> <description>
I have the following code in a view: def controller_details(request, object_id): controller = Controller.objects.get(pk=object_id)
I'm trying to use a class as a before filter for multiple controllers. Because
i have the following (simplified) domain classes class Filter { String name static hasMany
I have a Struts2 (2.1.8.1) web application. My web.xml looks like, <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
I have openSessionInView filter in web.xml. <filter> <filter-name>openSessionInView</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> </filter> And I have set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.