Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9247953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:51:51+00:00 2026-06-18T09:51:51+00:00

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

  • 0

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

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..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T09:51:52+00:00Added an answer on June 18, 2026 at 9:51 am

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

    This class is placed under portal-impl/src/com/liferay/portal/velocity/VelocityVariablesImpl.java.

    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".

    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).

    So just do

    $request.getServerName()
    

    and

    $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())
    

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

    Hope this helps.


    NOTA BENE !

    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

    • theme templates
    • layout templates
    • web-content templates
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get the IP address of the server from a JSP page?
I am using ajax in my jsp page to get all the values from
Can anybody help me how can I invoke a JSP page from a Servlet
I wrote a page called test.jsp to learn how to get data from a
I have a JSP page, so the user can insert the time when he/she
In JSP, I notice that I can't render ${} into HTML. After the page
My jsp page <select name=se> <option value=1>D1</option> <option value=2>D2</option> <option value=3>D3</option> </select> While the
On my JSP page, I defined some javascript with a variable that get value
I am having difficulty executing a MS SQL Server stored procedure from Java/jsp. I
I need to store cad files on my server, but I can't get the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.