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

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

Avatar

Avatar
Validate 1
Level 1
chaitanya_pai1
Level 1

Like

1 like

Total Posts

4 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
chaitanya_pai1
Level 1

Like

1 like

Total Posts

4 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
chaitanya_pai1
Level 1

15-10-2015

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

View Entire Topic

Avatar

Avatar
Validate 10
Level 2
SurendraKonatha
Level 2

Likes

5 likes

Total Posts

63 posts

Correct Reply

6 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 10
Level 2
SurendraKonatha
Level 2

Likes

5 likes

Total Posts

63 posts

Correct Reply

6 solutions
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile
SurendraKonatha
Level 2

23-11-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