找到你要的答案

Q:Why is renderRequest.contextPath empty in config.jsp but not view.jsp?

Q:为什么在config.jsp renderrequest.contextpath空但不是view.jsp?

I'm new to liferay and java so this is probably very simple.

I've successfully created portlet complete with a configuration.jsp file. In my portlet view.jsp I can successfully reference images:

<img src="${renderRequest.contextPath}/images/image1.png" />

But in my configuration.jsp the contextPath is empty.

QUESTION: What needs to be done in order to get the same path I get in my view.jsp?

I've created this pastebin showing my full code and this pastebin to show a simpler case.

我是新来的java版本,所以这可能是非常简单的。

我已经成功地创建了一个configuration.jsp文件完整的portlet。在我的portlet view.jsp我能够成功的参考图像:

<img src="${renderRequest.contextPath}/images/image1.png" />

但在我configuration.jsp contextpath是空的。

问题:需要做什么才能得到相同的路径,我从view.jsp?

我创造了这个展示我的全部代码粘贴,粘贴出一个简单的案例。

answer1: 回答1:

Use the below code.

<img src="<%=request.getContextPath()%>/images/image1.png"/>

Ensure that you have configured the portlet name properly in portlet.xml and web.xml

使用下面的代码。

<img src="<%=request.getContextPath()%>/images/image1.png"/>

确保你有适当的配置portlet名称xml和xml

java  jsp  liferay-6