How to get the page path using page url | Community
Skip to main content
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
maheshbabuvomaAccepted solution
Level 2
May 20, 2021 5:39 AM UTC

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

4 replies

maheshbabuvomaAccepted solution
Level 2
May 20, 2021 5:39 AM UTC

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

Translate
Employee
May 20, 2021 4:21 AM UTC

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

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

How can I get path from this? 

Translate
Prince_Shivhare
New Participant
May 20, 2021 4:36 AM UTC
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.
Translate
Prince_Shivhare
New Participant
May 20, 2021 4:07 AM UTC

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(); 
Translate