在 WebSphere 6 上将静态文件包含在具有可变文件名的 JSP 中

发布于 2024-09-02 16:55:35 字数 700 浏览 8 评论 0原文

我正在努力将静态文件包含到 Websphere 6.0.2.17 上的 JSP 中。我尝试了这个:

<% 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 %>"%>

路径是 /wcm/some/other/dir/page 我可以愉快地使用 out.write(inc) 打印出来。不幸的是,include(和jsp:include)根本不包含该文件。没有错误消息,但不包含内容...不过可以通过浏览器访问该文件。

我是否必须创建完整的 JSP 才能使其工作?我只需要一个 HTML 文件。

更新

因为迟早会包含更多页面,所以我决定为此案例创建一个自定义标签库。这样我就可以封装功能并在属性文件中设置静态内容的基目录。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乱世争霸 2024-09-09 16:55:35

尝试使用 RequestDispatcher.include():

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

这就像 include 指令,只不过每次包含的页面都会被处理(如果它是 JSP 或 servlet)。 include 指令仅在编译该指令所在的 JSP 文件时处理该页面一次。

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.

嘿嘿嘿 2024-09-09 16:55:35

我尝试通过 jsp:include 并且文件被完美包含。

请记住,您必须提供相对路径而不是绝对路径。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文