如何从 Liferay portlet 中的 URL 获取参数?
我在 Liferay 6 中使用开箱即用的 portlet 的 jsp,例如 feed.jspf:
String articleId =null;
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
articleId = httpReq.getParameter("articleId");
无论是在自定义 portlet 还是在 .jsp 文件中,它都会给出 null 值,但它应该有一个值。
I'm using jsp of out-of-box portlet like feed.jspf in Liferay 6:
String articleId =null;
HttpServletRequest httpReq = PortalUtil.getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
articleId = httpReq.getParameter("articleId");
It is giving a null value whether in custom portlet or in .jsp files, but it should have a value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
当然,您始终可以使用标准 HttpServletRequest 来检索参数。您可以使用 PortalUtil 类获取此请求,如下例所示:
Sure, you can always use the standard HttpServletRequest to retrieve your parameters from. You can get this request by using the PortalUtil class, like in the following example:
在我的 Liferay- JSP 中,我使用了这个:(
这结合了其他答案的智慧片段,特别是 Miguel Gil Martínez 在 2012 年 7 月 23 日 17:35 的回答
In my Liferay- JSP I use this:
(this combines fragments of wisdom from other answers, notably Miguel Gil Martínez's answer from 2012 Jul 23 at 17:35
使用 portlet 时,每个 HttpServletRequest 参数都有一个前缀(用于通知参数的“类型”)和一个后缀(用于表示 portlet 的哪个实例应该处理该参数)。因此,参数的名称不仅仅是“articleId”。我不知道您正在使用什么 portlet,但如果它是一个名为“example”的 portlet,通过战争部署,则参数将被称为
example_WAR_exampleportletwar_articleId_w2Xd
。但是,您不必处理如此复杂的问题。如果您正在某个已创建的 portlet 的 JSP 中工作,则应该有一个名为
renderRequest
的对象,它包含所有参数并抽象所有这些名称修改。因此,您不必检索原始 servlet 请求,而是使用它:如果未定义该对象,您只需在某处插入
标记,之后该对象将可用。HTH。让我们知道它是否有效!
When working with portlets, each HttpServletRequest paramenter has a prefix which informs the "type" of the parameter and a suffix expressing which instance of the portlet should process it. So, the name of the parameters is not just "articleId". I do not know what portlet are you working but if it was a portlet called, let's say, "example" deployed through a war the parameter would be called
example_WAR_exampleportletwar_articleId_w2Xd
.However, you do not have to deal with such complexity. If you are working within a JSP of some already created portlet, there should be an object called
renderRequest
which contains all parameters and abstracts all this name mangling. So, instead of retrieving the original servlet requestion you an use it:If this object is not defined, you just need to insert the
<portlet:defineObjects/>
tag somewhere and after this the object will be available.HTH. Let us know if it worked!
它对我有用:
It worked for me:
对于 JSF,我使用这个:
然后在你的 Facelet 中:
For JSF I use this:
Then in your facelet:
我尝试了你的解决方案,但渲染请求给了我一个例外,
所以这是另一个解决方案:
I tried ur solutions but render request it gives me an exception,
so this is another solution: