Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to get the page path using page url

Avatar

Level 5
1 Accepted Solution

Avatar

Correct answer by
Level 2

Hi @keerthana_hn 

 

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

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @keerthana_hn 

 

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

Avatar

Level 5

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

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

How can I get path from this? 

Avatar

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

Avatar

Correct answer by
Level 2

Hi @keerthana_hn 

 

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