You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tremal Nailk <tr...@gmail.com> on 2005/08/01 17:40:02 UTC

Exception handling in Struts

Hello, I'm trying to capture exceptions generated inside my jsp pages.
I wrote a piece of code like this into my jsp:

<% 
......
DatabaseException de = new DatabaseException("Test Exception for the
error page");
throw de;
.......
%>

I added these pieces in my web.xml and struts-config.xml

----------------------------web.xml-----------------------------
  <error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/error.jsp?code=exception</location>
  </error-page>
----------------------------web.xml-----------------------------
----------------------------struts-config.xml-----------------------------
  <global-exceptions>
    <exception key="error.application"
path="/error.jsp?code=exception" type="java.lang.Exception"/>
  </global-exceptions>
----------------------------struts-config.xml-----------------------------

I'm using the sslext SecureTilesRequestProcessor defined as:

  <controller processorClass="org.apache.struts.action.SecureTilesRequestProcessor"
/>

I'm not able to capture the exception thrown by the jsp page. The result is:

[ServletException in:/jsp/admin/groupListBody.jsp] Test Exception for
the error page'

written on the browser page, instead of the page generated by error.jsp

what's I'm doing wrong?

thanks in advance


-- 
TREMALNAIK

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


Re: Exception handling in Struts

Posted by Tremal Nailk <tr...@gmail.com>.
2005/8/1, Dave Newton <ne...@pingsite.com>:
> Probably want to use the web.xml exception stuff, then (error-page
> element, maybe?)

well, I'm using it (see my original posting), but the exception is not
caught, simply ignored. Anyway you are right when you say that the
exception should always be caught by the action class. I wanted to
make my jsp really secure whatever exception may be thrown, but
probabily I'm just a bit paranoid.

thanks

-- 
TREMALNAIK

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


Re: Exception handling in Struts

Posted by Dave Newton <ne...@pingsite.com>.
Tremal Nailk wrote:

>2005/8/1, Joe Germuska <Jo...@germuska.com>:
>  
>
>>>what's I'm doing wrong?
>>>      
>>>
>>Struts can't catch exceptions thrown by the JSP.  This is one reason
>>    
>>
>
>ok, anyway I'm looking for a way to catch all the exception thrown by
>may app. So throwing a dbexception was just an example. There is
>always something that may go wrong within a jsp.
>  
>
Probably want to use the web.xml exception stuff, then (error-page 
element, maybe?)

Ideally, there should be VERY little that can go wrong within a JSP; if 
presentation/everything else is handled within Struts, helper classes, 
custom tags, etc.--then the exceptions WILL be caught by struts.

What kind of exceptions do you anticipate being thrown by the JSP itself?

Dave


Re: Exception handling in Struts

Posted by Tremal Nailk <tr...@gmail.com>.
2005/8/1, Joe Germuska <Jo...@germuska.com>:
> >what's I'm doing wrong?
> 
> Struts can't catch exceptions thrown by the JSP.  This is one reason

ok, anyway I'm looking for a way to catch all the exception thrown by
may app. So throwing a dbexception was just an example. There is
always something that may go wrong within a jsp.

thanks, anyway

-- 
TREMALNAIK

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


Re: Exception handling in Struts

Posted by Joe Germuska <Jo...@Germuska.com>.
>what's I'm doing wrong?

Struts can't catch exceptions thrown by the JSP.  This is one reason 
(among many) why I would design something like this to do the 
database work in an action and deliver only data to the JSP.

Joe


At 4:40 PM +0100 8/1/05, Tremal Nailk wrote:
>Hello, I'm trying to capture exceptions generated inside my jsp pages.
>I wrote a piece of code like this into my jsp:
>
><%
>......
>DatabaseException de = new DatabaseException("Test Exception for the
>error page");
>throw de;
>.......
>%>
>
>I added these pieces in my web.xml and struts-config.xml
>
>----------------------------web.xml-----------------------------
>   <error-page>
>     <exception-type>java.lang.Exception</exception-type>
>     <location>/error.jsp?code=exception</location>
>   </error-page>
>----------------------------web.xml-----------------------------
>----------------------------struts-config.xml-----------------------------
>   <global-exceptions>
>     <exception key="error.application"
>path="/error.jsp?code=exception" type="java.lang.Exception"/>
>   </global-exceptions>
>----------------------------struts-config.xml-----------------------------
>
>I'm using the sslext SecureTilesRequestProcessor defined as:
>
>   <controller 
>processorClass="org.apache.struts.action.SecureTilesRequestProcessor"
>/>
>
>I'm not able to capture the exception thrown by the jsp page. The result is:
>
>[ServletException in:/jsp/admin/groupListBody.jsp] Test Exception for
>the error page'
>
>written on the browser page, instead of the page generated by error.jsp
>
>
>thanks in advance
>
>
>--
>TREMALNAIK
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org


-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"Narrow minds are weapons made for mass destruction"  -The Ex

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