From a struts-config.xml:
<!-- broker login, logout -->
<action path="/broker/login" type="LoginAction" name="brokerLoginForm" scope="request" validate="true" parameter="doBrokerLogin" input="/broker/brokerlogin.jsp">
<exception key="broker.login.error.authFailure" type="AuthenticationException" bundle="ExceptionMessages"/>
<forward name="success" path="/broker/brokerhome.jsp"/>
<forward name="failure" path="/shared/error.jsp"/>
</action>
The "key" attribute to the "exception" element is a message resources key, in the bundle specified by the "bundle" attribute. In my "ExceptionMessages" properties file, I have:
broker.login.error.authFailure=Sorry, you entered the wrong password
You are correct that, in your Action's execute method, you simply throw the Exception (in my example, an AuthenticationException), and the framework will catch it (since handling has been configured).
In my JSP I have this:
<%-- print exception messages if there are any, otherwise
print form validation error messages if there are any --%>
<logic:present name="org.apache.struts.action.EXCEPTION">
<html:errors bundle="EXCEPTION_MESSAGES"/>
</logic:present>
As someone pointed out in another Thread (I think it was Joe), my JSP code (logic:present) is not the most efficient, but it works. This prints the error message "Sorry, you entered the wrong password" at the top of the page if that message is present (if the Exception was thrown).
I have also used the "path" attribute in a global exception config, and it does work as expected. One thing I haven't done, however, is configure for a base class of the actual Exception. I always configure for the exact Exception class. So that could be it.
Hope this helps.
Erik
Wendy Smoak wrote:
I know I've tried this before, but so far I haven't gotten all the pieces properly arranged so it works. :/
I currently have code like this in an Action: try { benId = loginDAO.getBenId( asurite ); } catch ( TermsAcceptanceException ex ) { return mapping.findForward( "terms" ); }
In struts-config.xml: <action path="/denLogin" type="edu.asu.vpia.struts.DevilsDenLoginAction" name="loginForm" scope="request" validate="true" input="den.login.page"> <forward name="success" path="den.login.success"/> <forward name="terms" path="den.terms.agreement" > </action>
It's my impression that I don't need to catch the exception, that I *should* be able to let Action.execute(...) throw it and the framework can be configured to deal appropriately with it.
So I took out this line: <forward name="terms" path="den.terms.agreement" > And put in: <exception type="edu.asu.dao.DAOException" path="/WEB-INF/error.jsp" key="error.dao.exception"/>
And I just get a JSP with a stack trace. Although TermsAcceptanceException extends DAOException, it doesn't go to error.jsp.
Two questions... what is the 'key' attribute of <exception> used for, and can anyone tell what I'm doing wrong?
Thanks!
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]