Expand my Community achievements bar.

SOLVED

302 redirect from javascript to servlet

Avatar

Level 4

Hello ,

 

I am currently facing a strange behavior on dispatcher publish URL 

1>When i hit the servlet path  from JavaScript say /bin/servletpath , I get 200 status response from servlet

2>Now 2nd time when I hit the same path using  JavaScript say /bin/servletpath, it does not hit the servlet .Instead the server sends 302 as status response.

 

What could I do to resolve this issue. Not sure where to look into for this??

 

Regards,

Srinivas

1 Accepted Solution

Avatar

Correct answer by
Level 6

Hi @Srinivas_Opti,
It might be possible that the servlet response is getting cached. Make sure you exclude the same path from getting cached by doing changes in the dispatcher.any file.

Also, the 302 status means redirection. If there is any authentication or session timeout logic is written in your code make sure it is correct.

Other debugging options:

-- Try to hit your servlet using postman so that we can be sure JS is not responsible.
-- Set some loggers in your servlet and share there outputs here.
-- Use the browser's network tab to inspect headers and responses for both the first (200) and second (302) requests. This will help you identify if there’s a redirect URL in the second request.

Also, please share if  this issue also occur on local publish instance?

View solution in original post

4 Replies

Avatar

Community Advisor

Hi @Srinivas_Opti 
Using path-based servlets is not recommended. Instead, use servlets registered by resource type with selectors and extensions. Expose these servlets to the content path and access them using content path, selector, and extension for better maintainability and performance. 



Arun Patidar

Avatar

Community Advisor

Hi,

 

Is this AEM on-premise? It sounds like your publishers may be out of sync. Verify that your publishers have installed the same code and content, and then make sure there is no cache issue.

 

Hope this helps.



Esteban Bustamante

Avatar

Correct answer by
Level 6

Hi @Srinivas_Opti,
It might be possible that the servlet response is getting cached. Make sure you exclude the same path from getting cached by doing changes in the dispatcher.any file.

Also, the 302 status means redirection. If there is any authentication or session timeout logic is written in your code make sure it is correct.

Other debugging options:

-- Try to hit your servlet using postman so that we can be sure JS is not responsible.
-- Set some loggers in your servlet and share there outputs here.
-- Use the browser's network tab to inspect headers and responses for both the first (200) and second (302) requests. This will help you identify if there’s a redirect URL in the second request.

Also, please share if  this issue also occur on local publish instance?

Avatar

Administrator

@Srinivas_Opti Did you find the suggestions helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!



Kautuk Sahni