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
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

How to get the page path using page url

1 Accepted Solution
maheshbabuvoma
Correct answer by
Level 2
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
Prince_Shivhare
Level 9
Level 9

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(); 
keerthana_hn
Level 3
Level 3

@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
Level 9
Level 9
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.
maheshbabuvoma
Correct answer by
Level 2
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