How to get the current page path in a sling servlet that is called in the component dialog? | Community
Skip to main content
chaitanya_pai1
Level 2
October 16, 2015
Solved

How to get the current page path in a sling servlet that is called in the component dialog?

  • October 16, 2015
  • 2 replies
  • 16828 views

Hi,

I have a component that can be dragged and dropped onto a parsys in a page. The component dialog has a dropdown that gets the options from a servlet. 

In the servlet, I want to access the currentPage  path.   i.e the  page where the component was added.

I have tried to access it in the servlet using request.getRequestURI() and request.getResource().getPath() etc. But it points to the servlet path.

Can anyone let me know how I can the current page path in the servlet?

Thanks in Advance.

Regards,

Chaitanya Pai

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 BenZahler

hi Chaitanya,

check the referer http header, it should contain what you are looking for.

 

An alve would be to read the current path in the dialog's javascript and add it as a parameter to the servlet.

 

cheers,

Ben

2 replies

BenZahlerAccepted solution
Level 2
October 16, 2015

hi Chaitanya,

check the referer http header, it should contain what you are looking for.

 

An alve would be to read the current path in the dialog's javascript and add it as a parameter to the servlet.

 

cheers,

Ben

April 21, 2023

If we use 'referer' we may end-up with Critical sonar issue.

Instead we shall use 'RequestParametMap' and fetch 'item' key value, this is retuning exact page path.

November 23, 2015

Here's some examples for couple options:

  • OPTION 1 - Hidden Parameter with Sightly and Servlets

In your HTML form, add a hidden param:

        <input type="hidden" name="resourcePath" id="resourcePath" value="${currentPage.getPath}">

In your Servlet..

        if (slingHttpServletRequest.getParameter("resourcePath")!=null) { resourcePath = slingHttpServletRequest.getParameter("resourcePath");         }

Gives the path as /content/site1/en/abc.html

 

 

  • OPTION 2 - Just Servlets using HttpRequest Header
String resourcePath=""; // path of the page from where the request came from Enumeration values = slingHttpServletRequest.getHeaders("Referer"); if (values != null) { while (values.hasMoreElements()) { String url= (String) values.nextElement(); log.info("URL=" + url); } }       

Gives the path as http://localhost:4502/content/site1/en/abc.html