views:

85

answers:

2

I'm struggling with including a static file into my JSPs on Websphere 6.0.2.17. I tried this:

<% final String MY_DIR = ResourceBundle.getBundle("mybundle").getString("props.pages.wcm"); %>
<% final String page = ResourceBundle.getBundle("mybundle").getString("page"); %>
<% final String inc = MY_DIR + "/" + bonus; %>
<%@include file="<%= inc %>"%>

The path is /wcm/some/other/dir/page and I can happily print that out with out.write(inc). Unfortunatly the include (and the jsp:include) isn't including the file at all. There is no error message, but the content isn't included... The file is accessible via the browser though.

Do I have to create a full JSP for this to work? I just need a HTML file.

Update

Because there will be more pages to be included sooner or later I decided to create a custom taglib for this case. That way I can capsulate the functionality and set the base directory for my static content in a property file.

A: 

Try using RequestDispatcher.include():

<%
RequestDispatcher r = request.getRequestDispatcher(inc);
r.include(request, response);
%>

This is just like the include directive, except whatever page you are including will be processed every time (if it's a JSP or servlet). The include directive only processes the page once when the JSP file that the directive resides in is compiled.

Michael Angstadt
A: 

I tried through jsp:include and the file got included perfectly.

Keep in mind that you have to provide the relative path and not the absolute path.

RaviG
Did you tried this with a file *outside* of your application directory?
cringe
Yes I did and it is giving error to me.
RaviG