You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by NR031 <na...@cognizant.com> on 2009/04/27 10:34:21 UTC

Exception Handling in Struts 2.0.11

Hi,

   I am using Struts 2.0.11 and NetBeans 6.1. Is there any way to handle
exception in Struts 2?  

   I saw the tutorial given 
http://struts.apache.org/2.0.11/docs/exception-configuration.html
http://struts.apache.org/2.0.11/docs/exception-configuration.html , but it
doesn't contain a sample example that demonstrate the Exception Handling. I
am new to Struts so please explain with an example.


Thanks in advance,
-- 
View this message in context: http://www.nabble.com/Exception-Handling-in-Struts-2.0.11-tp23252025p23252025.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Exception Handling in Struts 2.0.11

Posted by NR031 <na...@cognizant.com>.
Hi Terry,

   My struts.xml looks like this :

<struts>
    <package name="AJAXLogin" extends="struts-default">
<global-results> 
            <result name="methodNotSupported" type="httpheader"> 
                405 
                The requested method is unsupported 
            </result> 
            <result name="error">/JSPPages/Exception.jsp</result> 
</global-results> 

        <global-exception-mappings> 
            <exception-mapping exception="java.lang.NoSuchMethodException"
result="methodNotSupported"/> 
            <exception-mapping
exception="java.lang.IllegalArgumentException" result="methodNotSupported"/> 
            <exception-mapping exception="java.lang.NullPointerException"
result="error"/> 
        </global-exception-mappings> 

<action name="Validation" class="cts.com.LoginValidation">
            <result name="input">/JSPPages/LoginPage.jsp</result>            
            <result name="Admin">/JSPPages/Admin.jsp</result>
            <result name="Common">/JSPPages/Common.jsp</result>
            <result name="blank">/JSPPages/Blank.jsp</result>
            <result name="error">/JSPPages/Error.jsp</result>             
</action>
</package>
</struts>

My action class LoginValidation.java contains getter and setter methods for
the textfield (username) and password (password) field defined in
LoginPage.jsp.

In the execute method of action class I am explicitely calling the
NullPointerException.
i.e.,

@Override
    public String execute() throws Exception {
throw new NullPointerException();
}

When this action class is called I should get the /JSPPages/Exception.jsp
page but currently I am not getting the actual page. Is it necessary to
define exception in the action tags of struts.xml

<action name="Validation" class="cts.com.LoginValidation">
<exception-mapping exception="java.lang.NullPointerException"
result="error"/>
</action>



Thanks in advance,
===============================================================================

Terry Gardner-2 wrote:
> 
> Can you be a little more clear about your ask? Using the examples in  
> the given URL, are you asking about:
> 
> 1. How to code exception.jsp?
> 2. How to code SQLExceptionAction.java?
> 3. What is on the ValueStack in these examples and an Exception occurs?
> 4. something else?
> 
> On Apr 27, 2009, at 4:34 AM, NR031 wrote:
> 
>>
>> Hi,
>>
>>   I am using Struts 2.0.11 and NetBeans 6.1. Is there any way to  
>> handle
>> exception in Struts 2?
>>
>>   I saw the tutorial given
>> http://struts.apache.org/2.0.11/docs/exception-configuration.html
>> http://struts.apache.org/2.0.11/docs/exception-configuration.html ,  
>> but it
>> doesn't contain a sample example that demonstrate the Exception  
>> Handling. I
>> am new to Struts so please explain with an example.
>>
>>
>> Thanks in advance,
>> -- 
>> View this message in context:
>> http://www.nabble.com/Exception-Handling-in-Struts-2.0.11-tp23252025p23252025.html
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
> 
> 
> ======
> 
> Terry Gardner
> Terry.Gardner@Sun.COM
> Skype: Terry_J_Gardner
> 
> "Vulcans never bluff." -- Spock
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Exception-Handling-in-Struts-2.0.11-tp23252025p23252800.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Exception Handling in Struts 2.0.11

Posted by Terry Gardner <Te...@Sun.COM>.
Can you be a little more clear about your ask? Using the examples in  
the given URL, are you asking about:

1. How to code exception.jsp?
2. How to code SQLExceptionAction.java?
3. What is on the ValueStack in these examples and an Exception occurs?
4. something else?

On Apr 27, 2009, at 4:34 AM, NR031 wrote:

>
> Hi,
>
>   I am using Struts 2.0.11 and NetBeans 6.1. Is there any way to  
> handle
> exception in Struts 2?
>
>   I saw the tutorial given
> http://struts.apache.org/2.0.11/docs/exception-configuration.html
> http://struts.apache.org/2.0.11/docs/exception-configuration.html ,  
> but it
> doesn't contain a sample example that demonstrate the Exception  
> Handling. I
> am new to Struts so please explain with an example.
>
>
> Thanks in advance,
> -- 
> View this message in context: http://www.nabble.com/Exception-Handling-in-Struts-2.0.11-tp23252025p23252025.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>


======

Terry Gardner
Terry.Gardner@Sun.COM
Skype: Terry_J_Gardner

"Vulcans never bluff." -- Spock


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Exception Handling in Struts 2.0.11

Posted by Lukasz Lenart <lu...@googlemail.com>.
2009/4/27 NR031 <na...@cognizant.com>:
>   I am using Struts 2.0.11 and NetBeans 6.1. Is there any way to handle
> exception in Struts 2?

Just define global result and put entries for given exceptions in
struts.xml, like below

        <global-results>
            <result name="methodNotSupported" type="httpheader">
                <param name="error">405</param>
                <param name="errorMessage">The requested method is
unsupported</param>
            </result>
            <result name="error">/jsp/error.jsp</result>
        </global-results>

        <global-exception-mappings>
            <exception-mapping
exception="java.lang.NoSuchMethodException"
result="methodNotSupported"/>
            <exception-mapping
exception="java.lang.IllegalArgumentException"
result="methodNotSupported"/>
            <exception-mapping
exception="java.lang.NullPointerException" result="error"/>
        </global-exception-mappings>


Regards
-- 
Lukasz
http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org