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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:26:01+00:00 2026-05-18T10:26:01+00:00

I had a JSP file with a c:redirect tag that would forward along a

  • 0

I had a JSP file with a c:redirect tag that would forward along a user to another page.

<!-- Yes, I know this loop is probably unnecessary, but I'm not fluent in jsp and have determined it is not the problem. :)  -->
<c:if test="${cmd.numberOfResults == 1}"> 
    <c:forEach items="${cmd.matches}" var="someVar">
        <c:redirect url="/loadThatResultInfo.html"/>
    </c:forEach>
</c:if>

The old implementation of the command object is needs updating (where I come in). The way I’m doing so is by creating a generic “search result” object which contains an instance of that old object (for now). I get that instance through a property in that generic class, so my code is now this:

<c:if test="${cmd.genericSearchObject.numberOfResults == 1}"> 
    <c:forEach items="${cmd.genericSearchObject.matches}" var="acct">
        <jsp:forward page="/loadThatResultInfo.html"/> <!-- new try! -->
        <c:redirect url="/loadThatResultInfo.html"/>   <!-- old try... -->
        <% response.sendRedirect("/loadThatResultInfo.html"); %> <! new try! -->
    </c:forEach>
</c:if>

Each of those three tries all result in IllegalStateExceptions of some sort. Why does this change cause the exception, especially considering that the lines involved — the redirect, not the changed/bound class instances — are causing the problem?

Back-end changes were made accordingly, referencing the property within my new encompassing “generic” class to satisfy the old functionality. I know this works because all related functionality, beside what I’m writing about, works.

Research online indicates:
– I can’t redirect/forward after a submission has already been submitted. Then how was I able to do it before?
– Attempt to flush an already-cleared buffer causes this. What changed that makes it cleared now as opposed to the older (first) implementation?
– The size of the page’s buffer needs to be bigger. THIS is one I don’t understand and would really love for the stackoverflow community to address; I can see my new class causing size changes that would need changes to be dealt with.

——- ANOTHER ANSWER! ——-

First and foremost, ALWAYS SET UP THE SITUATION IN THE CODE as described by the marked answer. However… if you’re stuck and don’t want to do that, here’s a quick fix: javascript!

<script type="text/javascript">
    location='./yourPageToGoTo.html'
</script>
  • 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-18T10:26:02+00:00Added an answer on May 18, 2026 at 10:26 am

    JSP is part of the response. You’re attempting to change the response destination in a JSP instead of in a controller. If you do this halfway in a JSP, then it’s too late, because the HTTP response headers may already have been sent (the response is then in committed state). This is a point of no return and an illegal state for changing the response. It’s too late then. Any attempt will result in the servletcontainer to throw IllegalStateException: response already committed.

    To fix this, you need to put this piece code in the very top of JSP file and pray that the response hasn’t already been committed at that point (which will usually happen after writing about 2KB of data to the response, depending on the servletcontainer config). However, JSP is still the wrong place for the job, you should rather do this in the controller, before forwarding the response to the JSP (or to instruct from within the model the controller somehow to do the job, when you’re using a MVC framework).

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

Sidebar

Related Questions

I followed THIS but had no luck. My . jsp file has in head
I have a button on my .jsp page that I would like to act
Had a page that was working fine. Only change I made was to add
I've got a jsp file, which includes another jsp file to check some values
I have read this jsp page encoding problem and this Save Chinese characters with
I have this simple JSP page in Eclipse and the first line in the
I can't seem to solve this. Originally the JSP code had a function in
Its been a while since I had to do some Java/JSP... I have a
Had a coworker ask me this, and in my brain befuddled state I didn't
Had a good search here but can't see anything that gets my mind in

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.