在 WebSphere 6 上将静态文件包含在具有可变文件名的 JSP 中
我正在努力将静态文件包含到 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 RequestDispatcher.include():
这就像 include 指令,只不过每次包含的页面都会被处理(如果它是 JSP 或 servlet)。 include 指令仅在编译该指令所在的 JSP 文件时处理该页面一次。
Try using RequestDispatcher.include():
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.
我尝试通过
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.