Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8303175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:27:41+00:00 2026-06-08T17:27:41+00:00

I have a problem with my ajax redirection on response. The redirection works perfectly,

  • 0

I have a problem with my ajax redirection on response.
The redirection works perfectly, but when, later, I have to return a Boolean with response, it returns the redirection.

Here is the code. The concerned lines have comments :

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Worker extends HttpServlet {

    private static final long serialVersionUID = 1L;
    private static String firstName = "";
    private static String lastName = "";
    private static boolean doAnimWheel = false;
    private static String portion;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // begin recovering form
        Worker.firstName = request.getParameter("firstName");
        Worker.lastName = request.getParameter("lastName");

        response.sendRedirect("launch.html"); // TODO find why it blocks response
        // end recovering form

        String param = request.getParameter("srcId");
        if(param != null) {
            if(param.equals("launch")) {
                Worker.doAnimWheel = new Boolean(request.getParameter("doAnimWheel")).booleanValue();
                return;
            }
            else if(param.equals("wheel")) {
                response.setContentType("text/plain");
                PrintWriter out = response.getWriter();
                out.print(Worker.doAnimWheel); // Here I have to return my Boolean, but it return launch.html
                out.flush();
                out.close();
                return;
            }
            else if(param.equals("result")) {
                Worker.portion = request.getParameter("portion");
                Worker.doAnimWheel = new Boolean(request.getParameter("doAnimWheel")).booleanValue();
                return;
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T17:27:42+00:00Added an answer on June 8, 2026 at 5:27 pm

    I think the problem is that you always send the redirect at the beginning of your method

        response.sendRedirect("launch.html"); // TODO find why it blocks response
        // end recovering form
    

    Java documentation for the sendRedirect method HttpServletResponse states: “After using this method, the response should be considered to be committed and should not be written to.”

    What you try to return later is evidently ignored.

    You may want to move the sendRedirect calling to the branches of code that actually need to perform the redirect, like this:

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
            // begin recovering form
            Worker.firstName = request.getParameter("firstName");
            Worker.lastName = request.getParameter("lastName");
    
            String param = request.getParameter("srcId");
    
            if(param.equals("launch")) {
                            Worker.doAnimWheel = new Boolean(request.getParameter("doAnimWheel")).booleanValue();
                            response.sendRedirect("launch.html");
                            return;
                        }
                        else if(param.equals("wheel")) {
                            response.setContentType("text/plain");
                            PrintWriter out = response.getWriter();
                            out.print(Worker.doAnimWheel); // Here I have to return my Boolean, but it return launch.html
                            out.flush();
                            out.close();
                            return;
                        }
                        else if(param.equals("result")) {
                            Worker.portion = request.getParameter("portion");
                            Worker.doAnimWheel = new Boolean(request.getParameter("doAnimWheel")).booleanValue();
                            response.sendRedirect("launch.html");
                            return;
                        }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem in getting and testing the return value of ajax. my code
I have unusual problem with AJAX toolkit ColorPickerExtender. Javascript code works fine it changes
have a problem with my ajax code. I have some links and a content
I have a problem with an AJAX call in JQuery. It works on Chrome,
I have problem with ajax and php.I have next code $(form).submit(function() { var poruka
I am passing variables to submit file via AJAX but I have problem when
here's the thing: i built my site with SEO friendly urls...but i have problem
i have problem.. for(a=1;a<10;a++){ $(.div).append(<div id=+a+></div>) $.ajax({ url: file.php, data: a=+a, type: POST, async:
i have a little problem with my Ajax calls. Maybe i do not have
I have this problem that my sites uses alot of ajax and when a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.