如何从Liferay速度模板获取服务器名称和服务器端口?

编程入门 行业动态 更新时间:2024-10-28 14:32:29
本文介绍了如何从Liferay速度模板获取服务器名称和服务器端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在jsp页面中,我们可以使用以下命令获取服务器名称和服务器端口 request.getServerName()和request.getServerPort().

In jsp page we can get Server Name and Server Port by using request.getServerName() and request.getServerPort().`

由于我们无法从Liferay速度模板中获取HttpServletRequest,是否还有其他方法可以 获得服务器名称和服务器端口?请回答一个小的代码段.

As we can't get HttpServletRequest from Liferay velocity template, Is there any other way to get both Server Name and Server Port ? Please answer with a small code snippet..

推荐答案

在Liferay资源中,您可以找到com.liferay.portal.velocity.VelocityVariablesImpl.

In your Liferay sources you can find com.liferay.portal.velocity.VelocityVariablesImpl.

此类位于portal-impl/src/com/liferay/portal/velocity/VelocityVariablesImpl.java下.

如果您检查速度上下文的所有条目(如velocityContext.put(String key, Object value)之类的行),并且特别检查insertVariables方法中的那些条目,您会发现这会将您的httpServletRequest公开为"request".

If you check all entries to velocity context (lines like velocityContext.put(String key, Object value)) and specially the ones in the insertVariables method, you'll see that this exposes you httpServletRequest under the name "request".

因此,您可以在模板中使用键$request来访问请求对象,就像访问其他任何速度上下文对象一样.

Therefore, in your template you access your request object as any other velocity context object with the key $request.

然后,该对象将可用于其所有方法和属性(如果已公开).

This object will, then, be usable with all it's methods and properties (if public).

所以就做

$request.getServerName()

$request.getServerPort()

此外,如果要将速度变量设置为其中之一,请执行以下操作

Furthermore, if you want to set a velocity variable to one of those, just do as follows

#set ($my_amazing_variable = $request.getServerPort())

然后您就可以将$my_amazing_variable用作任何常规的速度垃圾.

You'll then be able to use $my_amazing_variable as any regular velocity litteral.

希望这会有所帮助.

NOTA BENE!

NOTA BENE !

请注意,您无权访问Liferay中所有类型的速度模板下的完全相同的变量和宏集. 有不同的集合

Note that you do not have access to the exact same set of variables and macros under all types of velocity templates in Liferay. There are different sets for

  • 主题模板
  • 布局模板
  • 网络内容模板

更多推荐

如何从Liferay速度模板获取服务器名称和服务器端口?

本文发布于:2023-08-07 14:27:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1319624.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   端口   模板   速度   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!