Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top