Jasper exception when including a html file in jsp

How do I incude a static html file in the jsp in a portal application? By using <c:import> or <jsp:include> I am able to achieve it. This is working if the requested file exits. In my case the file name is formed dynamically and so I cannot assure that such an html file exists. Incorrect html file names gives a jasper exception and my entire portlet is not getting rendered. Is there a way to check if the file exits? How can this jasper exception be handled?

Any way to render the rest of the content in the jsp escaping this tag alone?

Message was edited by:

Deborah_Rachel

[616 byte] By [Deborah_Rachela] at [2007-11-27 9:34:38]
# 1

The trick would be to check if the resource is there before you try importing it.

So you need to validate the filename you are given.

The following code snippet should do it

String requestedResource = ?;

RequestDispatcher rdTest = request.getRequestDispatcher(requestedResource);

if (rdTest != null){

// resource is present go ahead and import it

}

else {

// resource not present - what to do in this case?

}

I would probably put this code in the controller before we start rendering the final JSP view because then it could divert to an appropriate page.

Including it on the JSP, I would probably encapsulate it in a custom tag.

An alternative might be to catch the exception

<c:catch var="caughtException">

<c:import url="${myUrl}"/>

</c:catch>

<c:if test="${not empty caughtException">

The url does not exist.

</c:if>

At least I think it would work :-)

Cheers,

evnafets

evnafetsa at 2007-7-12 22:59:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks a lot. I tried to catch the exception. It worked while I tried including a script(js file). But while I tried to include a html file which does not exist I am getting File not found along with the path in the site.
Deborah_Rachela at 2007-7-12 22:59:23 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...