Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

How to get the page path using page url

Avatar

Level 4
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 4

@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