0

Is there a way to configure Tomcat to die automatically if there's an error loading a web app (i.e. the app throws an exception), or if it can't find any apps at all? I'd rather my users get a connection problem than a blank white page.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
dostende
  • 253
  • 2
  • 8

1 Answers1

1

You could do

System.exit(-1);

instead of

throw SomeException("Failed to initialize webapp");

However, when you deploy this to a 3rd party or shared host which allows this, the serveradmin isn't going to be happy with this.

I'd rather review your model/view/controller logic so that the enduser get a (custom) HTTP 500 error page instead of a blank page. Are you sure you aren't writing Java code in JSP files? Throwing exceptions inside JSP files may namely cause this.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • This might not work if the security manager is enabled. Edit: I meant `System.exit(-1);` The rest are valid points. – Vineet Reynolds Jun 20 '11 at 15:45
  • @Vineet: on many 3rd party/shared hosts maintained by a smart serveradmin invoking this method is indeed disallowed. And not without reason :) However, Tomcat in unmodified trim allows it. It sounds much like that the OP (or its company) is maintaining Tomcat themselves, so they may have full control over it. – BalusC Jun 20 '11 at 15:47
  • You're right; an error page does sound better. I don't know much about the architecture of the app I'm working with, so I don't know if the JSP files use Java code, but even if my appBase directory is completely empty and no apps load, I get blank white pages no matter the URL. – dostende Jun 20 '11 at 17:18
  • The blank pages are because there's no ROOT directory in my appBase. Adding one, even an empty one, causes Tomcat to serve generic 404 errors where appropriate, which is better than blank pages. – dostende Jun 20 '11 at 18:03