title: Java+Vaadin+tomcat Handling Exception using web.xml
body: <p><strong>Requirement:</strong></p>
  
  <p>I want to show an error page when ever we get any exception(i.e.,NullPointer,IndexOutofBoundsException etc) in Server Console.</p>
  
  <p><strong>System Requirement:</strong></p>
  
  <p>We are using apache tomcat 7.0.61,maven 3.2.3,Spring and Vaadin 7 (For UI Framework).</p>
  
  <p><strong>Ours WEB.XML file:</strong></p>
  
  <pre><code>&lt;context-param&gt;
  ..............
  &lt;/context-param&gt;
  
  &lt;context-param&gt;
  &lt;param-name&gt;contextClass&lt;/param-name&gt;
  &lt;param-value&gt;
  org.springframework.web.context.support.AnnotationConfigWebApplicationContext
  &lt;/param-value&gt;
  &lt;/context-param&gt;
   .....
  &lt;listener&gt;
  &lt;listener-class&gt;
      org.springframework.web.context.ContextLoaderListener
  &lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;servlet&gt;
  &lt;servlet-name&gt;Vaadin Application Servlet&lt;/servlet-name&gt;
  &lt;servlet-class&gt;com.vaadin.server.VaadinServlet&lt;/servlet-class&gt;
  &lt;init-param&gt;
      &lt;description&gt;Vaadin UI to display&lt;/description&gt;
      &lt;param-name&gt;UI&lt;/param-name&gt;
      &lt;param-value&gt;com.lone.ui.LoneUI&lt;/param-value&gt;
  &lt;/init-param&gt;
  &lt;init-param&gt;
      &lt;description&gt;Application widgetset&lt;/description&gt;
      &lt;param-name&gt;widgetset&lt;/param-name&gt;
      &lt;param-value&gt;com.lone.ui.AppWidgetSet&lt;/param-value&gt;
  &lt;/init-param&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;Vaadin Application Servlet&lt;/servlet-name&gt;
  &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>So i browsed and tried with some of the scenarios:</p>
  
  <p><strong>Scenario 1)</strong> </p>
  
  <p>First i have configured </p>
  
  <pre><code>&lt;error-page&gt;
  &lt;exception-type&gt;java.lang.Throwable&lt;/exception-type&gt;
  &lt;location&gt;/error&lt;/location&gt;
  &lt;/error-page&gt;
  (or)
  &lt;error-page&gt;
  &lt;exception-type&gt;java.lang.Exception&lt;/exception-type&gt;
  &lt;location&gt;/error&lt;/location&gt;
  &lt;/error-page&gt;
  </code></pre>
  
  <p>in web.xml file and then i have written the Controller class by using the @RequestMapping("/error") in the method level but this scenario not worked.</p>
  
  <p><strong>Scenario 2)</strong></p>
  
  <p>Same with the above web.xml file i have written the Servlet class as </p>
  
  <pre><code>@WebServlet(value = {"/error"},asyncSupported = true)
  public class ExceptionHandling extends VaadinServlet{
  @Override
  protected VaadinServletService getService() {
      System.out.println("First if i display the sout message then i can  Navigate to the Error Page....");
      return super.getService();
  }
  }
  </code></pre>
  
  <p>But this is also not at worked.</p>
  
  <p><strong>Scenario 3)</strong></p>
  
  <p>Same with the above web.xml file i have written the Servlet class by extending the HTTPServlet but still unable to display the sout message.</p>
  
  <p><strong>Scenario 4)</strong>
  I have tried with Spring @ControllerAdvice and @Exception handler Annotation still i am unable to display the Error Page</p>
  
  <p><strong>Main Requirement:</strong></p>
  
  <p>I need to configure the Exceptions in the Web.xml file,so that when we get any exceptions in the server console it should hit the web.xml file and should navigate to the error page.</p>
  
  <p>Could you please suggest me to complete the requirement because i have been working on this requirement from past 2 days.</p>
  
  <p>Thanks in advance.</p>