browser url in sling model | Community
Skip to main content
manikanthar1295
New Participant
September 22, 2022
Solved

browser url in sling model

  • September 22, 2022
  • 3 replies
  • 2513 views

Hi Team,

 

How I  can get browser URL in sling model for example  if the browser URL is https://www.xyz.com/ i need to get this url  in sling model so that i need to do some update based on condition.

can some one help here.

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

above is tested and working you can use like that 

 

3 replies

AdobeID24
AdobeID24Accepted solution
New Participant
September 27, 2022

above is tested and working you can use like that 

 

HeenaMadan
New Participant
September 22, 2022

In Sling model, take request object

 @Self
 private SlingHttpServletRequest request;

and call request.getRequestURI() to get domain

manikanthar1295
New Participant
September 23, 2022

@heenamadan ,

 

I tried how u explained but always i am getting request is null;

Any other option i can try ??

New Participant
September 23, 2022

Could you please share your model class?

New Participant
September 22, 2022

Hi,

 

If you are adapting request to your model, then you can use 

@SlingObject
private SlingHttpServletRequest request;

then, get uri from request using 

request.getRequestURI()