How to get the page path using page url | Community
Skip to main content
Adobe Employee
May 20, 2021
Solved

How to get the page path using page url

  • May 20, 2021
  • 3 replies
  • 1759 views
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 maheshbabuvoma

Hi @keerthana_h_n 

 

if you are in sling model you can get path using below code 

PageManager pageManager= resource.getResourceResolver().adaptTo(PageManager.class);

Page currentPage = pageManager.getContainingPage(resource);

 

Thanks,

Mahesh

3 replies

Prince_Shivhare
Community Advisor
Community Advisor
May 20, 2021

Hi @keerthana_h_n 

 

If you are using sling models, then using the resource you can get the path of a specific node.

you can use resource.getPath();

If you have a page URL then you can use it like this -

 

URL url1=new URL("http://localhost:4502/content/share/coke/en/light/report-template/file_report_template.html?wcmmode=...");  

    url1.getPath(); 
Adobe Employee
May 20, 2021

@prince_shivhare I'm getting url in string format like this.

String requestRefererPath = request.getHeader(HttpHeaders.REFERER);

How can I get path from this? 

Prince_Shivhare
Community Advisor
Community Advisor
May 20, 2021
if you are getting a url in string format, you can use the same Java Net Url to get the path from specific url. the same way which i have mentioned below.
maheshbabuvomaAccepted solution
Level 2
May 20, 2021

Hi @keerthana_h_n 

 

if you are in sling model you can get path using below code 

PageManager pageManager= resource.getResourceResolver().adaptTo(PageManager.class);

Page currentPage = pageManager.getContainingPage(resource);

 

Thanks,

Mahesh