You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by José Antonio Delgado Trujillo <ja...@gmail.com> on 2016/03/22 21:13:37 UTC

Specific Exception Handling

In the example of exception - handling explains how to configure an
specific exception for an action.

It is simple, only write the exception-mapping into the action node. But i
don't know how it works and why we need two result nodes.

[image: Imágenes integradas 1]

I understood that if the method throwSecurityException of the Register
class throws SecurityBreachException, the action returns the result login
and then it redirects to login.jsp but:


   - In which part of the app use the URL action actionspecificexeption?
   - If the method throwsSecurityException always throws
   SecurityBreachException why do we need the other result?



-- 
Un saludo,
José A.

Re: Specific Exception Handling

Posted by José Antonio Delgado Trujillo <ja...@gmail.com>.
OK,
I saw in the github the URL cause actions exceptions in the index,jsp but i
dont't still understand the two result in the actionspecificexption.

2016-03-22 20:13 GMT+00:00 José Antonio Delgado Trujillo <ja...@gmail.com>
:

> In the example of exception - handling explains how to configure an
> specific exception for an action.
>
> It is simple, only write the exception-mapping into the action node. But i
> don't know how it works and why we need two result nodes.
>
> [image: Imágenes integradas 1]
>
> I understood that if the method throwSecurityException of the Register
> class throws SecurityBreachException, the action returns the result login
> and then it redirects to login.jsp but:
>
>
>    - In which part of the app use the URL action actionspecificexeption?
>    - If the method throwsSecurityException always throws
>    SecurityBreachException why do we need the other result?
>
>
>
> --
> Un saludo,
> José A.
>



-- 
Un saludo,
José A.

RE: Specific Exception Handling

Posted by Martin Gainty <mg...@hotmail.com>.
                                                                                                Date: Tue, 22 Mar 2016 20:13:37 +0000
Subject: Specific Exception Handling
From: jadtmat@gmail.com
To: user@struts.apache.org

In the example of exception - handling explains how to configure an specific exception for an action.
It is simple, only write the exception-mapping into the action node. But i don't know how it works and why we need two result nodes.


I understood that if the method throwSecurityException of the Register class throws SecurityBreachException, the action returns the result login and then it redirects to login.jsp but:
In which part of the app use the URL action actionspecificexeption?
MG>when op first executes login.jsp as seen below:   <action name="actionspecificexception" class="org.apache.struts.register.action.Register" method="throwSecurityException">
     <exception-mapping exception="org.apache.struts.register.exceptions.SecurityBreachException" 
          result="login" />
      <result>/register.jsp</result>
      <result name="login">/login.jsp</result>
   </action>If the method throwsSecurityException always throws SecurityBreachException why do we need the other result?

MG><result>/register.jsp</result> is default result when processed by org.apache.struts.register.action.Register that returns SUCCESS
MG>https://struts.apache.org/docs/exception-handling.html
-- 
Un saludo,José A.
MG>¿Claro?MG>/Saludos Cordiales/MG>Martín
 		 	   		  

Re: Specific Exception Handling

Posted by Lukasz Lenart <lu...@apache.org>.
2016-03-22 21:13 GMT+01:00 José Antonio Delgado Trujillo <ja...@gmail.com>
:

> In the example of exception - handling explains how to configure an
> specific exception for an action.
>
> It is simple, only write the exception-mapping into the action node. But i
> don't know how it works and why we need two result nodes.
>

You can define exception-mapping in two places: package-wide and
action-wide when action-wide takes precedence over package-wide


>
> [image: Imágenes integradas 1]
>
> I understood that if the method throwSecurityException of the Register
> class throws SecurityBreachException, the action returns the result login
> and then it redirects to login.jsp but:
>

Nope, it doesn't return "login" result, it throws the
SecurityBreachException and now framework catches it and search for
matching exception-mapping based on the exception's class


>
>    - In which part of the app use the URL action actionspecificexeption?
>
> Here
https://github.com/apache/struts-examples/blob/master/exception-handling/src/main/webapp/index.jsp#L30


>
>    -
>    - If the method throwsSecurityException always throws
>    SecurityBreachException why do we need the other result?
>
> To  simulate real life app ;-) Normally methods don't throw exception all
the time


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/