Servlet Path Format to provide in RequestDispatcher | Community
Skip to main content
Level 2
July 29, 2022
Solved

Servlet Path Format to provide in RequestDispatcher

  • July 29, 2022
  • 3 replies
  • 1254 views

Hi All, 

 

Can Anyone Provide me a working Solution for below :

 

I need to forward servlet request from Servlet 1 to Servlet 2.

RequestDispatcher rd = request.getRequestDispatcher("/com/testform");
rd.forward(request, respo);

 where "/com/testform" is my Servlet 2 Sling Path.
It's not able to forward and seems like not able to find this above path.
Please provide me a working solution ASAP.

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 GanthiRa1

@priyankadatta 

Best practice to register a servlet is using resource type. If you still want to go with path, then by default only '/bin/' is allowed in the OSGI sling servlet resolver and dispatcher.any file. So please check whether the path '/com/testform/' is allowed on both the places.

3 replies

Shivam153
Level 3
July 29, 2022

A Single request can be created once at a time. In your case, you are trying to create multiple servlet requests.

Level 2
July 29, 2022

No.

Please check RequsetDispatch implementation and how to redirect request from one servlet to another.

Level 2
July 29, 2022

@shivam153 

Hi, I don't find here creating multiple servlet request.

If you can check the code snippet above,

 This is the syntax that we follow .

To forward any servlet request from one to another, it involves 2 steps as below:

1. Create request dispatcher object (here it is 'rd')

2. and use that object in forward method.

 

RequestDispatcherOBJECT.forward(SlingRequest, SlingResponse)

GanthiRa1Community AdvisorAccepted solution
Community Advisor
July 31, 2022

@priyankadatta 

Best practice to register a servlet is using resource type. If you still want to go with path, then by default only '/bin/' is allowed in the OSGI sling servlet resolver and dispatcher.any file. So please check whether the path '/com/testform/' is allowed on both the places.

Level 2
August 3, 2022

hello @priyankadatta ,

Hope you have already got the solution for the above. If not please check the below Url if it helps

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/calling-a-servlet-from-another-servlet/td-p/463299

 

Please make sure your servlet path is configured as allowed paths in the Configuration Manager