• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Error Page Configuration in web.xml

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
{
s.toUpperCase();
}
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
 
Ranch Hand
Posts: 329
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.

Regards
Jatan
 
Self destruct mode activated. Instructions for deactivation encoded in this tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic