wood burning stoves 2.0*
The moose likes Struts and the fly likes Error Page Configuration in web.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Error Page Configuration in web.xml" Watch "Error Page Configuration in web.xml" New topic

Error Page Configuration in web.xml

Sindhura Lakshmi

Joined: Jun 18, 2009
Posts: 13
Hi ,

I am trying configure an error page in my struts webapplication.

I have configured the errorpage tag in my web.xml.

In my Action class i need to redirect to the error page only when some specific values are retrned from DB.

So i tried throwing an exception as shown below:

if (code!=0&&msg!=4){

throw new Exception();


The above part of the code is in execute () of the Action class which has throws Exception declaration already.

Now the problem is when i am throwing the exception i am able to seeit in the logs but it is not getting redirected to errorpage.

When I remove the "throw new Excetion()" code and try to generate some exception like below:
String s=null;

if(code!=0 &&msg!=4)
In the above case it is working fine and i am able to redirect it to the error page.

Please let me know why the throw new Exception part is not working.

THanks in Advance
Shankar Tanikella
Ranch Hand

Joined: Jan 30, 2011
Posts: 329

Hi Lakshmi,
First things first, Throwing an exception of generic type is a very bad Idea.

Which version of struts are you using?
if 1.x, what is the global exception mentioned in struts config (if it was mentioned)
I would prefer to throw an user defined exception and configure the same in struts config based on type.

Have Fun with Java
little,little.. little by little makes a lot..
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296


You can define the Global exception in configuration file through which you can redirect to error page in struts. Explore <exception/> in struts.
Second thing you can also print the exception in that jsp page but you need to implement the exception handler which will send the object to jsp page.

Make changes in your code as shankar suggested.

Don't get me started about those stupid light bulbs.
subject: Error Page Configuration in web.xml
Similar Threads
JSF : redirect errors to error page
JSF 2.0 exception handling - Is it necessary to catch the exceptions in the Bean classes ?
Directing a servlet to the jsp error page
org.apache.jasper.JasperException: java.lang.NullPointerException when JSP page refreshes
Same exception different handle in tomcat4.1 and weblogic6.1