gpt4 book ai didi

jsf - 无法在 jsf 中获取 servletcontext 路径

转载 作者:行者123 更新时间:2023-12-04 20:02:52 24 4
gpt4 key购买 nike

我写了一个liferay richfaces portlet。但是我无法在 web-inf 文件夹中获取 css 路径或图像。我的 portlet 配置是

 <portlet>
<portlet-name>testLR6_PB3_RF4</portlet-name>
<instanceable>true</instanceable>

<render-weight>1</render-weight>
<ajaxable>true</ajaxable>
<header-portlet-css>/resources/css/style.css</header-portlet-css>
<header-portlet-javascript>/js/eims.js</header-portlet-javascript>
<footer-portlet-javascript>/js/fileupload.js</footer-portlet-javascript>
</portlet>

在我的 jsf 页面中

<link href="${facesContext.externalContext.requestContextPath}/resources/css/style.css" rel="stylesheet" type="text/css" />

<div class="floatleft1"><img src="${facesContext.externalContext.requestContextPath}/resources/images/eims_logo.jpg" /></div>

如何获取资源路径。

这是我的 java servletcontext 代码

FacesContext context = FacesContext.getCurrentInstance();
ServletContext servletContext= (ServletContext) context.getCurrentInstance().getExternalContext().getContext();
String path=servletContext.getRealPath("/");
MainBean mainBean = new MainBean();
mainBean.getUserBean().setUserPath(path);

最佳答案

看看how can i have access to my files that placed in WEB-INF folder .可能会有帮助。此外,如果您使用的是 JSF 2.0,Facelets,您可以简单地在您的 jsf 页面中获取上下文根作为

<ui:param name="root" value="#{request.contextPath}" />

无论您需要访问上下文根中的文件,您都可以访问它们(假设示例)

<img src="#{root}/resources/images/sample.jpg" />

在java端,你可以获取上下文路径为

String contextPath = FacesContext.getCurrentInstance().getExternalContext().getContextName();

希望这对您有所帮助。

关于jsf - 无法在 jsf 中获取 servletcontext 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19043569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com