Servlet Redirect in Ajax Request

JonasGomes June 21, 2018

Hi team,

I wanna redirect the request that contains "X-Requested-With: XMLHttpRequest" in the header. I know cant i do response.sendRedirect(url) method in ajax call, so i tried:

httpRequest.getRequestDispatcher("myservlet").forward(req, res);
//or
httpRequest.getRequestDispatcher("myservlet").include(req, res);
 

but the same problem, the client is not redirected to  my servlet.

and too tried to return a xml response with this:

<?xml version="1.0" encoding="UTF-8"?><partial-response><redirect url="jiraurl/plugins/servlet/nopermission"></redirect></partial-response>

but nothing happens.

I'm stuck in this problem for weeks, if have any that can help me i will be very grateful.

Thanks.

1 answer

1 accepted

1 vote
Answer accepted
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2018

Hi @JonasGomes

  1. Next time i think it will be better if you rise a question in the developer community https://community.developer.atlassian.com/
  2. So i understand you have a servlet, can you explain what exactly your servlet do and what you want to do? it seems to me like you try to do something in the wrong way.
JonasGomes June 22, 2018

Hi Nit Haimov, Thanks for answering.

When my filter is triggered on a certain occasion (url == myregex), the user should be forwarded to my servlet.

That's basically what I need to do. But my approach for Ajax Async request does not work.

I'll also ask in the other forum.

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2018

Your servlet is something you created from your own plugin right?

JonasGomes June 22, 2018

Thats Right

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 22, 2018

So in your ajax call use:

window.location.replace(AJS.params.baseURL+"/plugins/servlet/myservlet");
JonasGomes June 22, 2018

Sorry, i think you do not what i meant. Sorry. Awful english.

I will detail my problem on community developer.

Thanks for you attention.

Suggest an answer

Log in or Sign up to answer