title: How do I avoid "Exception handling request to" javax.servlet.ServletException when redirecting?
body: <p>I have logic in my backing bean that redirects if there is a session timeout.</p>
  <pre><code>            FacesContext.getCurrentInstance().getExternalContext().setResponseStatus(responseCode);
              FacesContext.getCurrentInstance().getExternalContext().setResponseHeader(&quot;Location&quot;, redirectURL);
              FacesContext.getCurrentInstance().responseComplete();
  </code></pre>
  <p>However, the page that is being loaded still attempts to render, and throws this error:</p>
  <pre><code>2021-11-27 08:02:50,774 ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request to /dashboard/mypage.htm: javax.servlet.ServletException
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:236)
      at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129)
      at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:294)
      at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
      at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
      at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61)
      at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:131)
  </code></pre>
  <pre><code>Caused by: java.lang.NullPointerException
      at javax.el.ELUtil.buildParameters(ELUtil.java:699)
      at javax.el.ELUtil.invokeMethod(ELUtil.java:243)
      at javax.el.BeanELResolver.invoke(BeanELResolver.java:338)
      at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:198)
      at com.sun.el.parser.AstValue.getValue(AstValue.java:111)
      at com.sun.el.parser.AstValue.getValue(AstValue.java:179)
      at com.sun.el.parser.AstDeferredExpression.getValue(AstDeferredExpression.java:39)
      at com.sun.el.parser.AstCompositeExpression.getValue(AstCompositeExpression.java:44)
      at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:202)
      at org.apache.myfaces.view.facelets.el.ContextAwareTagValueExpression.getValue(ContextAwareTagValueExpression.java:93)
      at javax.faces.component._DeltaStateHelper.eval(_DeltaStateHelper.java:372)
      at org.primefaces.component.menuitem.UIMenuItemBase.getUrl(UIMenuItemBase.java:91)
      at org.primefaces.renderkit.MenuItemAwareRenderer.encodeOnClick(MenuItemAwareRenderer.java:67)
      at org.primefaces.component.menu.BaseMenuRenderer.encodeMenuItem(BaseMenuRenderer.java:111)
      at org.primefaces.component.menu.BaseMenuRenderer.encodeMenuItem(BaseMenuRenderer.java:69)
      at org.primefaces.component.tieredmenu.TieredMenuRenderer.encodeElements(TieredMenuRenderer.java:124)
      at org.primefaces.component.menubutton.MenuButtonRenderer.encodeMenu(MenuButtonRenderer.java:147)
      at org.primefaces.component.menubutton.MenuButtonRenderer.encodeMarkup(MenuButtonRenderer.java:68)
      at org.primefaces.component.menu.BaseMenuRenderer.encodeEnd(BaseMenuRenderer.java:50)
  </code></pre>
  <p>How can I get the view to stop loading on this workflow? It's obvious that, since the redirect occurred, the backing bean hasn't loaded everything and therefore EL expressions that depend on such objects being loaded, are failing.</p>
  <p>I don't want to generate the error because this causes my admins grief because of the error emails that get generated. They can't tell if it is a real error or not.</p>