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 7440501
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:51:45+00:00 2026-05-29T10:51:45+00:00

I have a servlet with an overridden doGet method in a Dynamic Web App

  • 0

I have a servlet with an overridden doGet method in a Dynamic Web App 3.0 targeted to GlassFish 3.1.

I’m studying for OCEJWCD exam and trying to memorize which circumstances throw which exceptions.

Due to Tomcat 6.0 only supporting Servlet 2.5 API, I have to use Glassfish 3 and I’m very confused with following situation.

Numerous old sources state that:

A response is committed as soon as the servlet starts to write
anything to the output stream. If you attempt a re-direct after the
response is committed you will receive an IllegalStateException error.

However Servlet 3.0 Final specification Section 5.3 states:

If data has been written to the response buffer, but not returned to
the client (i.e. the response is not committed), the data in the
response buffer must be cleared and replaced with the data set by
these methods. If the response is committed, these methods must throw
an IllegalStateException

What I want to know is, considering the PrintWriter.print() is committing the response, why don’t these lines throw IllegalStateException?

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    String url = "http://someurl.com/";
    PrintWriter out = response.getWriter();
    out.print("This will be written into response buffer");
    response.sendRedirect(url); // sendRedirect() after writing into buffer
}

I have to note that, I am able to fetch exceptions from GlassFish server log, I can clearly see that HttpServletRequest.getRequestDispatcher().forward(req,res); followed by a HttpServletResponse.sendRedirect(url); does indeed throw an IllegalStateException in GlassFish container.

  • 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-05-29T10:51:45+00:00Added an answer on May 29, 2026 at 10:51 am

    The fact is that PrintWriter.print() may commit the response. This happens if the buffer is full or if there’s no buffering at all. You can check its size by calling ServletResponse.getBufferSize().

    ServletResponse.flushBuffer() or PrintWriter.flush() will definitely commit the response.

    So if PrintWriter.print() was committing the response, then the HttpServletResponse.sendRedirect() would indeed throw an IllegalStateException.

    See also Servlet Specification, section 5.1 Buffering.

    And btw., there’s no RequestDispatcher.dispatch(). 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Under JBoss 4.0.1SP1, I have a servlet that makes multiple, concurrent calls to web
I have this in my applicationContext.xml <bean class=org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter /> <mvc:annotation-driven conversion-service=conversionService/> <bean id=conversionService class=org.springframework.context.support.ConversionServiceFactoryBean>
i have the following action class: package com.pendulum.web; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest;
I have been trying to get a basic example of a servlet endpoint to
I have servlet in my web application that serves images, and when I visit
I have a servlet that is used for many different actions, used in the
I have a servlet running in an Oracle OCCAS server. Currently I map some
I have a servlet that I would like to run within ColdFusion MX 7.
I have a servlet S which handles callbacks from a 3rd party site. The
We have a servlet which occupies more virtual memory on the server due to

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.