Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在jsf中获取servletcontext路径_Jsf_Jsf 2_Servletconfig - Fatal编程技术网

无法在jsf中获取servletcontext路径

无法在jsf中获取servletcontext路径,jsf,jsf-2,servletconfig,Jsf,Jsf 2,Servletconfig,我已经编写了一个liferay richfaces portlet。但是我无法在web inf文件夹中获取css路径或图像。 我的portlet配置是 <portlet> <portlet-name>testLR6_PB3_RF4</portlet-name> <instanceable>true</instanceable> <render-weight>1</render-weight&

我已经编写了一个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>
看一看。这可能会有帮助。此外,如果您使用的是JSF2.0 Facelets,那么只需在JSF页面中获取上下文根即可

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

希望这能有所帮助。

我仍然无法获取图像。你能在这里发布更新吗?你现在做的改变是什么?欢迎使用swd无标题文档。上述代码没有您无法获取的图像或img标签的参考。你能粘贴没有显示的图像标签的代码吗?谢谢@vagabond是我的错,我把资源文件夹放在了webinf而不是web内容文件夹中
FacesContext context = FacesContext.getCurrentInstance();
        ServletContext servletContext= (ServletContext) context.getCurrentInstance().getExternalContext().getContext();
        String path=servletContext.getRealPath("/");
        MainBean mainBean = new MainBean();
        mainBean.getUserBean().setUserPath(path);
<ui:param name="root" value="#{request.contextPath}" />
<img src="#{root}/resources/images/sample.jpg" />
String contextPath = FacesContext.getCurrentInstance().getExternalContext().getContextName();