Handling exception in an included JSP ..

Z

zakasbanda

Guys,

I need your help. Here is the problem ...

Following is typical structure of my jsps

<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<tiles:insert page="/layout/layout.jsp" flush="true">
<tiles:put name="title" value="sometitle" />
<tiles:put name="tabstate" value="sometabstate" />
<tiles:put name="menu" value="/menu.jsp" />
<tiles:put name="header" value="/header.jsp" />
<tiles:put name="body" value="/body.jsp" />
<tiles:put name="footer" value="/footer.jsp" />
</tiles:insert>

In the included/nested jsps (header, body et) .... I use usebeans, as
in following example,

<jsp:useBean id="data" type="java.lang.String" scope="request" />

As you can see, I am using "type" and therefore "data" must be present
in scope when the jsp is rendered. However I can not stop the user
from accessing this jsp direct and request might not have "data" set
in attribute. In this case the jsp blows up ugly on the browser, as
follows...

[ServletException in:/header.jsp] bean data not found within scope'

I would like to forward to some nice error.jsp if this happens. Could
you guys please help me out?

I have tried following in web.xml,

<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>

While this solution work from top level jsp, it does not seem to be
kicking if there is an exception at the nested jsp level.

Thanks
 
N

Nostalgia

Guys,

I need your help. Here is the problem ...

Following is typical structure of my jsps

<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

<tiles:insert page="/layout/layout.jsp" flush="true">
        <tiles:put name="title" value="sometitle" />
        <tiles:put name="tabstate" value="sometabstate" />
        <tiles:put name="menu" value="/menu.jsp" />
        <tiles:put name="header" value="/header.jsp" />
        <tiles:put name="body" value="/body.jsp" />
        <tiles:put name="footer" value="/footer.jsp" />
</tiles:insert>

In the included/nested jsps (header, body et) .... I use usebeans, as
in following example,

<jsp:useBean id="data" type="java.lang.String" scope="request" />

As you can see, I am using "type" and therefore "data" must be present
in scope when the jsp is rendered. However I can not stop the user
from accessing this jsp direct and request might not have "data" set
in attribute. In this case the jsp blows up ugly on the browser, as
follows...

[ServletException in:/header.jsp] bean data not found within scope'

I would like to forward to some nice error.jsp if this happens. Could
you guys please help me out?

I have tried following in web.xml,

    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/error.jsp</location>
    </error-page>

While this solution work from top level jsp, it does not seem to be
kicking if there is an exception at the nested jsp level.

Thanks

Hi!
I think you can specify error page directive in the jsp where you
suspect an exception.
<%@ page errorPage="/error.jsp" %>

Further, you can decide how different exceptions be handled in
error.jsp.
I hope this was useful.
 
Z

zakasbanda

I need your help. Here is the problem ...
Following is typical structure of my jsps
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:insert page="/layout/layout.jsp" flush="true">
        <tiles:put name="title" value="sometitle" />
        <tiles:put name="tabstate" value="sometabstate" />
        <tiles:put name="menu" value="/menu.jsp" />
        <tiles:put name="header" value="/header.jsp" />
        <tiles:put name="body" value="/body.jsp" />
        <tiles:put name="footer" value="/footer.jsp" />
</tiles:insert>
In the included/nested jsps (header, body et) .... I use usebeans, as
in following example,
<jsp:useBean id="data" type="java.lang.String" scope="request" />
As you can see, I am using "type" and therefore "data" must be present
in scope when the jsp is rendered. However I can not stop the user
from accessing this jsp direct and request might not have "data" set
in attribute. In this case the jsp blows up ugly on the browser, as
follows...
[ServletException in:/header.jsp] bean data not found within scope'
I would like to forward to some nice error.jsp if this happens. Could
you guys please help me out?
I have tried following in web.xml,
    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/error.jsp</location>
    </error-page>
While this solution work from top level jsp, it does not seem to be
kicking if there is an exception at the nested jsp level.

Hi!
I think you can specify error page directive in the jsp where you
suspect an exception.
<%@ page errorPage="/error.jsp" %>

Further, you can decide how different exceptions be handled in
error.jsp.
I hope this was useful.- Hide quoted text -

- Show quoted text -

Thank you very much. I specify the error page (as you suggested) in
nested jsps and it does forward it to error.jsp in case of error.
However my earlier understanding was that following entry in web.xml
would do the job and I may not need to put <%@ page errorPage="/
error.jsp" %> on top of every jsp.
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.jsp</location>
</error-page>
This entry in web.xml obviously does not seem to be working for nested
jsps.
Do you have any idea (or point me to some resource) that clarifies the
error/exception handling on jsps ....

Appriciate your pointers.
Thanks
 
N

Nostalgia

On Oct 14, 5:28 am, "(e-mail address removed)" <[email protected]>
wrote:
Guys,
I need your help. Here is the problem ...
Following is typical structure of my jsps
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<tiles:insert page="/layout/layout.jsp" flush="true">
        <tiles:put name="title" value="sometitle" />
        <tiles:put name="tabstate" value="sometabstate" />
        <tiles:put name="menu" value="/menu.jsp" />
        <tiles:put name="header" value="/header.jsp" />
        <tiles:put name="body" value="/body.jsp" />
        <tiles:put name="footer" value="/footer.jsp" />
</tiles:insert>
In the included/nested jsps (header, body et) .... I use usebeans, as
in following example,
<jsp:useBean id="data" type="java.lang.String" scope="request" />
As you can see, I am using "type" and therefore "data" must be present
in scope when the jsp is rendered. However I can not stop the user
from accessing this jsp direct and request might not have "data" set
in attribute. In this case the jsp blows up ugly on the browser, as
follows...
[ServletException in:/header.jsp] bean data not found within scope'
I would like to forward to some nice error.jsp if this happens. Could
you guys please help me out?
I have tried following in web.xml,
    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/error.jsp</location>
    </error-page>
While this solution work from top level jsp, it does not seem to be
kicking if there is an exception at the nested jsp level.
Thanks
Hi!
I think you can specify error page directive in the jsp where you
suspect an exception.
<%@ page errorPage="/error.jsp" %>
Further, you can decide how different exceptions be handled in
error.jsp.
I hope this was useful.- Hide quoted text -
- Show quoted text -

Thank you very much. I specify the error page (as you suggested) in
nested jsps and it does forward it to error.jsp in case of error.
However my earlier understanding was that following entry in web.xml
would do the job and I may not need to put <%@ page errorPage="/
error.jsp" %> on top of every jsp.
<error-page>
   <exception-type>java.lang.Exception</exception-type>
   <location>/error.jsp</location>
</error-page>
This entry in web.xml obviously does not seem to be working for nested
jsps.
Do you have any idea (or point me to some resource) that clarifies the
error/exception handling on jsps ....

Appriciate your pointers.
Thanks

Hi!
Exception entry in web.xml will take care of all exceptions raised by
servlets in your application.
For nested jsp's or say, all jsp you need to specify the errorPage
using <@ page ...> directive.
Here's a good read: http://java.sun.com/products/jsp/html/exceptions.fm.html

regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top