title: org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error applying layout : main
body: <p>What does this error message means and how can I fix it?</p>
  
  <pre><code>Sep 16, 2013 2:28:59 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [default] in context with path [] threw exception
  org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error applying layout : main
      at org.codehaus.groovy.grails.web.sitemesh.SpringMVCViewDecorator.render(SpringMVCViewDecorator.java:74)
      at org.codehaus.groovy.grails.web.sitemesh.SpringMVCViewDecorator.render(SpringMVCViewDecorator.java:52)
      at org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.doFilter(GrailsPageFilter.java:161)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:369)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
      at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:112)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
      at org.codehaus.groovy.grails.plugins.springsecurity.RequestHolderAuthenticationFilter.doFilter(RequestHolderAuthenticationFilter.java:40)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      at org.codehaus.groovy.grails.plugins.springsecurity.MutableLogoutFilter.doFilter(MutableLogoutFilter.java:79)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
      at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:381)
      at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:168)
      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.codehaus.groovy.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:69)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.codehaus.groovy.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
      at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:724)
  Caused by: org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: Error executing tag &lt;browser:isMobile&gt;: Cannot create a session after the response has been committed
      at org.codehaus.groovy.grails.web.servlet.view.GroovyPageView.createGroovyPageException(GroovyPageView.java:205)
      at org.codehaus.groovy.grails.web.servlet.view.GroovyPageView.handleException(GroovyPageView.java:182)
      at org.codehaus.groovy.grails.web.servlet.view.GroovyPageView.renderWithTemplateEngine(GroovyPageView.java:153)
      at org.codehaus.groovy.grails.web.servlet.view.GroovyPageView.renderMergedOutputModel(GroovyPageView.java:84)
      at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:263)
      at org.codehaus.groovy.grails.web.sitemesh.SpringMVCViewDecorator.render(SpringMVCViewDecorator.java:67)
      ... 55 more
  Caused by: org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag &lt;browser:isMobile&gt;: Cannot create a session after the response has been committed
      at org.codehaus.groovy.grails.web.pages.GroovyPage.throwRootCause(GroovyPage.java:529)
      at org.codehaus.groovy.grails.web.pages.GroovyPage.invokeTag(GroovyPage.java:472)
      at sun.reflect.GeneratedMethodAccessor555.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
      at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:989)
      at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
      at gsp_testpackage_layoutsmain_gsp$_run_closure1.doCall(gsp_testpackage_layoutsmain_gsp.groovy:74)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
      at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at groovy.lang.Closure.call(Closure.java:411)
      at groovy.lang.Closure.call(Closure.java:405)
      at org.codehaus.groovy.grails.web.taglib.GroovyPageTagBody.executeClosure(GroovyPageTagBody.java:206)
      at org.codehaus.groovy.grails.web.taglib.GroovyPageTagBody.captureClosureOutput(GroovyPageTagBody.java:108)
      at org.codehaus.groovy.grails.web.taglib.GroovyPageTagBody.call(GroovyPageTagBody.java:219)
      at org.codehaus.groovy.grails.plugins.web.taglib.SitemeshTagLib.captureTagContent(SitemeshTagLib.groovy:47)
      at org.codehaus.groovy.grails.plugins.web.taglib.SitemeshTagLib.captureTagContent(SitemeshTagLib.groovy)
      at sun.reflect.GeneratedMethodAccessor851.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
      at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1030)
      at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)
      at org.codehaus.groovy.grails.plugins.web.taglib.SitemeshTagLib$_closure1.doCall(SitemeshTagLib.groovy:122)
      at sun.reflect.GeneratedMethodAccessor966.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
      at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at groovy.lang.Closure.call(Closure.java:411)
      at org.codehaus.groovy.grails.web.pages.GroovyPage.invokeTagLibClosure(GroovyPage.java:503)
      at org.codehaus.groovy.grails.web.pages.GroovyPage.invokeTag(GroovyPage.java:425)
      at org.codehaus.groovy.grails.web.pages.GroovyPage$invokeTag.callCurrent(Unknown Source)
      at gsp_testpackage_layoutsmain_gsp.run(gsp_testpackage_layoutsmain_gsp.groovy:126)
      at org.codehaus.groovy.grails.web.pages.GroovyPageWritable.writeTo(GroovyPageWritable.java:205)
      at org.codehaus.groovy.grails.web.servlet.view.GroovyPageView.renderWithTemplateEngine(GroovyPageView.java:149)
      ... 58 more
  Caused by: java.lang.IllegalStateException: Cannot create a session after the response has been committed
      at org.apache.catalina.connector.Request.doGetSession(Request.java:2886)
      at org.apache.catalina.connector.Request.getSession(Request.java:2316)
      at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:898)
      at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:910)
      at sun.reflect.GeneratedMethodAccessor799.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaBeanProperty.getProperty(MetaBeanProperty.java:57)
      at groovy.lang.MetaBeanProperty$getProperty.call(Unknown Source)
      at org.codehaus.groovy.grails.plugins.web.ServletsGrailsPluginSupport$_enhanceServletApi_closure1.doCall(ServletsGrailsPluginSupport.groovy:38)
      at sun.reflect.GeneratedMethodAccessor552.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at org.codehaus.groovy.runtime.metaclass.ClosureMetaMethod.invoke(ClosureMetaMethod.java:80)
      at groovy.lang.ExpandoMetaClass.getProperty(ExpandoMetaClass.java:1150)
      at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
      at org.codehaus.groovy.runtime.callsite.PojoMetaClassGetPropertySite.callGetProperty(PojoMetaClassGetPropertySite.java:41)
      at org.geeks.browserdetection.UserAgentIdentService.getUserAgent(UserAgentIdentService.groovy:57)
      at org.geeks.browserdetection.UserAgentIdentService.this$3$getUserAgent(UserAgentIdentService.groovy)
      at org.geeks.browserdetection.UserAgentIdentService$this$3$getUserAgent.callCurrent(Unknown Source)
      at org.geeks.browserdetection.UserAgentIdentService.isMobile(UserAgentIdentService.groovy:216)
      at org.geeks.browserdetection.UserAgentIdentService$isMobile.call(Unknown Source)
      at org.geeks.browserdetection.BrowserTagLib$_closure1_closure43.doCall(BrowserTagLib.groovy:32)
      at org.geeks.browserdetection.BrowserTagLib$_closure1_closure43.doCall(BrowserTagLib.groovy)
      at sun.reflect.GeneratedMethodAccessor720.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:272)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:64)
      at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
      at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:69)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
      at org.geeks.browserdetection.BrowserTagLib.handle(BrowserTagLib.groovy:233)
      at org.geeks.browserdetection.BrowserTagLib.this$2$handle(BrowserTagLib.groovy)
      at sun.reflect.GeneratedMethodAccessor649.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
      at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1030)
      at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
      at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:145)
      at org.geeks.browserdetection.BrowserTagLib$_closure1.doCall(BrowserTagLib.groovy:32)
      at sun.reflect.GeneratedMethodAccessor719.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
      at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
      at groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:1110)
      at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
      at groovy.lang.Closure.call(Closure.java:411)
      at org.codehaus.groovy.grails.web.pages.GroovyPage.invokeTagLibClosure(GroovyPage.java:503)
      at org.codehaus.groovy.grails.web.pages.GroovyPage.invokeTag(GroovyPage.java:425)
      ... 116 more
  </code></pre>
  
  <p>I use the Grails <a href="http://grails.org/plugin/browser-detection" rel="nofollow">Browser Detection Plugin</a>. This might be the source of the error.</p>