302 redirect from javascript to servlet | Community
Skip to main content
Level 3
September 10, 2024
Solved

302 redirect from javascript to servlet

  • September 10, 2024
  • 4 replies
  • 992 views

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

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 kapil_rajoria

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?

4 replies

arunpatidar
Community Advisor
Community Advisor
September 10, 2024

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
EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
September 10, 2024

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
kapil_rajoria
Community Advisor
kapil_rajoriaCommunity AdvisorAccepted solution
Community Advisor
September 11, 2024

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?

kautuk_sahni
Community Manager
Community Manager
September 13, 2024

@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