Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Action class error handling

Status
Not open for further replies.

greygirl

Programmer
Jun 12, 2002
34
0
0
US
In my business components, I try catch sqlexception and some other exceptions. I have dynaactionforms. How do I redirect the user to a generic error page?
For instance in my action class I call a method to get an arraylist of query data. If it returns null then how do I route the user to a generic error page?
thanks
greygirl
 
You can add error within the execute() and return forward to input page. Here is an example:

Code:
public ActionForward execute(ActionMapping mapping,
                             ActionForm form,
                             HttpServletRequest request,
                             HttpServletResponse response)
           throws IOException, ServletException {


     //  process here
     boolean hasError = someProcess();

     // find errors
     if (hasError) {
 
        ActionErrors errors = new ActionErrors();

        errors.add(ActionMessages.GLOBAL_MESSAGE,
       	           new ActionMessage("errors.name.duplicated"));
     
        saveErrors(request, errors);

        // find error, return to the input page.
        return mapping.getInputForward();

     } else {
        // process ok return the next page
        return mapping.findForward("sucess");
     }
}
 
Thanks for the reply.
// find error, return to the input page.
return mapping.getInputForward();
Does this mean, in my struts-config, in action mapping I have to give an attribute input and specify like this:
<action path="/rates"
type="wages.rateAction"
name="wagedefaultForm"
input="/errorpage.jsp"
parameter="/pages/wages/rates.jsp">
<forward name="success" path=".com.wages.report" />
</action>
so getInputForward() will go to errorpage.jsp.
Because this throws ClassCastException
greygirl
 
Correct. You need to define the input page in your action mapping in stucts-config. Usually, that will be the form page, when error (usually validation error) occured, you want to go back to the input page to allow user to correct the form and submit again.

The "input" page is also used by the form bean, if validation failed, it will automatically forward to the input page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top