Expand my Community achievements bar.

SOLVED

Servlet Path Format to provide in RequestDispatcher

Avatar

Level 2

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.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@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.

View solution in original post

5 Replies

Avatar

Level 4

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

Avatar

Level 2

No.

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

Avatar

Level 2

@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)

Avatar

Correct answer by
Community Advisor

@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.

Avatar

Level 3

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-ano...

 

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