File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception handling

 
Artemesia Lakener
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a web app using struts, I have JSP that calls some Action classes and eventually forward to other JSPs. Assuming I don't want to catch any of the exceptions in the Action classes, how should "implement" the error handling ? A fellow suggest I just type the dummy </html:erros> in every JSP pages, does that make sense ? should I define some <global exception> in the struts-config.xml ?
 
martin jose
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

What type of exceptions you want to handle?
<html:errors> is normally used for form validation.

<html:text property="name"/><html:errors property="name"/>

you can put code like this in the JSP, so that if there is any error with the data you entered in the name field can be notified to the user.

if you simply put <html:errors> , it will display all the errors.

You must create this error entries either in your Form or Action.

validate()
{
ActionErrors errors = new ActionErrors();
if (name.length()==0 || name == null)
errors.add("name",new ActionError("error.emptychk"));
return errors;
}


if you want handle other error cases associated with the action, you can put the code in try-catch blocks and inside the block you can write the code for forwarding to a corresponding error pages

try
{
.........
..........

}
catch(Exception e)
{
mapping.findForward("error");
}

Also you can associate some Exceptions with an action. You can define each oof these exceptions with the help of a Custom exception class or an Existing Exception class. You can also specify where you forward on these exceptions.

Hope this will help you.

Regards,
Martin
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am more interested in other types of exceptions like SQLException, classnotfound exception, IO exception, etc. Since the web application includes a series of JSP and Actions (JSP1-->Action 1-->JSP 2 -->Action 2-->JSP 3 -->Action 3-->...), where should I catch the exceptions ? should I catch them in the last Action only ?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic