File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Exception Handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Exception Handling" Watch "Exception Handling" New topic

Exception Handling


Joined: Jan 04, 2004
Posts: 2
Can anyone tell me how to do exception handling in struts. ?For example if a field already exists in database...the user should get a msg as "data already exists".
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
I do something along the following:
error occurs
create ActionErrors object
create ActionMessage with error text
add ActionMessage to ActionErrors object
add ActionErrors to request
return to page request originated from
pick up ActionErrors object with <logic:messagesPresent> tag in jsp
display error to user
Rick Hightower
Ranch Hand

Joined: Feb 20, 2002
Posts: 350
You could also do declarative exception handling in the struts config file.

Rick Hightower is CTO of Mammatus which focuses on Cloud Computing, EC2, etc. Rick is invovled in Java CDI and Java EE as well. linkedin,twitter,blog
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Please take a moment for reading our naming policy. As it stands, your display name fails to comply with the policy so I'll have to ask you to change it accordingly.
More specifically, the policy allows the use of initials only for the first name, not the last name. You should also use a space instead of the underscore character.
Thanks. And welcome to the JavaRanch!

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
I agree. Here's the link:
subject: Exception Handling
It's not a secret anymore!