开发者

Include static file in JSP with variable filename on WebSphere 6

开发者 https://www.devze.com 2022-12-31 19:16 出处:网络
I\'m struggling with including a static file into my JSPs on Websphere 6.0.2.17. I tried this: <% final Strin开发者_如何学Cg MY_DIR = ResourceBundle.getBundle(\"mybundle\").getString(\"props.pages

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

<% final Strin开发者_如何学Cg 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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消