${request.serverName} not returning expected value | Community
Skip to main content
August 26, 2021

${request.serverName} not returning expected value

  • August 26, 2021
  • 2 replies
  • 6245 views

Hello Community - I am using the request object ${request.serverName} to retrieve the domain name. If I access the dispatcher URL, it is returning the AEM Publish instance name(which is incorrect) instead of the actual domain name of the page I am trying to access.

 

i.e If I try to access the page: https://www.example.com/test.html - It should return "www.example.com"

Accessing AEM Publish instance: https://aempublish:8080/test.html - should return "aempublish"

 

I have even verified the dispatcher configs (VirtualHost entrues). Can someone tell me how can I fix this?

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

VeenaVikraman
Community Advisor
Community Advisor
August 27, 2021

@test1234567 You might have to try ${request.requestURL.toString} 

 

https://stackoverflow.com/a/56376338/8671041

 

Thanks

Veena ✌

August 27, 2021

Actually request.ServerName is showing the value of the publish instance instead of dispatcher URL domain name. The same is working as expected in other environment.

Asutosh_Jena_
Community Advisor
Community Advisor
August 27, 2021

Hi @test1234567 

 

I am using the below code in Servlet to get the request domain along with port.

String domain = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();  

 

Thanks!

August 27, 2021

It works in one environment but doesn’t work in other environment. In the working environment. We don’t use any servlet. We are using only thr request object.

Asutosh_Jena_
Community Advisor
Community Advisor
August 27, 2021

When you say it works in one env and does not work in other. I did not get it.

You can read the value from request and check the value and if it's working in one env, it should work in other as well. what's the difference in environment?