Results 1 to 14 of 14
  1. #1
    saran87 is offline Member
    Join Date
    Jul 2009
    Location
    india
    Posts
    9
    Rep Power
    0

    Default java.lang.IllegalStateException: Cannot forward after response has been committed

    wat it means..

  2. #2
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    This means that an attempt has been made to forward the request after at least a partial response has been sent to the client. This is illegal.

  3. #3
    saran87 is offline Member
    Join Date
    Jul 2009
    Location
    india
    Posts
    9
    Rep Power
    0

    Default this my code

    <%
    String Invoiceno=request.getParameter("controlNo").trim() ;
    //System.out.println(Invoiceno);
    %>
    <input type="hidden" name="Invoiceno" value="<%=request.getParameter("controlNo")%>">
    <%
    int countvalue=0;
    DBConnectionManager connectionManager = null;
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet rst = null;
    try
    {
    connectionManager = DBConnectionManager.getInstance();
    connection = connectionManager.getConnection(Path.database);
    statement = connection.prepareStatement("SELECT Invoiceno, InvoiceDate,CustID,ShipmentMethod FROM tblInvoice WHERE Invoiceno = ?");
    statement.setString(1 ,Invoiceno);
    rst = statement.executeQuery();
    while(rst.next())
    {
    countvalue++;

    DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
    DateFormat df2 = new SimpleDateFormat("MM/dd/yyyy");

    String invoiceDate="";
    invoiceDate=rst.getString(2);

    String invoiceDt=invoiceDate;
    java.util.Date date = df1.parse(invoiceDt);
    String invDate = df2.format(date);
    //System.out.println(invDate);
    %>
    <tr style="background-color: #CCCDDB;">
    <td><b>InvoiceNo: </b><%= rst.getString(1)%></td>
    <td><b>Invoice Date(mm/dd/yyyy): </b>

    <input readonly="readonly" name="invoiceDate" id="invoiceDate" value="<%=invDate%>">
    <a onclick="displayDatePicker('invoiceDate', this);" style="cursor:pointer">
    <IMG src="/martin/images/newCaln.jpe" border=0>
    </a>
    </td>
    <td><b> Customer ID: </b><%= rst.getString(3)%></td>
    <td><b>Shipment Method: </b><%= rst.getString(4)%></td>
    </tr>
    <%
    }
    if(countvalue==0)
    {
    RequestDispatcher dispatcher=getServletContext().getRequestDispatche r("/jsp/Invoice/searchInvoice.jsp?&display=true"+"&InvNo="+Invoice no);
    dispatcher.forward(request,response);
    }

    }

    catch(Exception e)
    {
    System.out.println("invoiceEdit.jsp @@@@@@@@@@@@@@@@@@@@"+e);
    }
    finally
    {
    connectionManager.freeConnection(Path.database,con nection);
    }
    %>

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    That is quite a mess.
    First get rid of all that Java code from JSP.
    JSPs should never contain Java code. In fact your exception will probably go away as soon as you move all that Java code into servlets and helper classes.
    JSPs should be used for presentation only.

  5. #5
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    you should move the java code to action class in servlet etc

    and in the java code, you loop for the resultset and store information in Hashtable/LinkedHashMap etc

    chech the size of Hashtable/LinkedHashMap, if size is 0, forward to other page
    if size > 0, then action map to target location jsp
    and use jstl etc to do the presentation
    Java Code:
    <c:if test="{$xxx.size > 0}">
        <c:forEach ...>
            ....
        </c:forEach>
    </c:if>

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default

    Quote Originally Posted by mtyoung View Post
    you should move the java code to action class in servlet etc

    and in the java code, you loop for the resultset and store information in Hashtable/LinkedHashMap etc
    Why a Hash anything?
    The usual collection to use for returning the results of a query is a bog standard ArrayList.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,185
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    "bog standard"? I've never heard that term before.
    Bog standard. Though I could have sworn I knew it in the 70s...but I suppose that doesn't really count as "recorded".

  9. #9
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    "The basic unrefined article"?

    I'm beginning to like it already.

  10. #10
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    Hi,
    Added to the above replies one more thing I want to tell is U can't output anything before forward.That is why u got the above error.

    -Regards
    Ramya
    Ramya:cool:

  11. #11
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Quote Originally Posted by RamyaSivakanth View Post
    Hi,
    Added to the above replies one more thing I want to tell is U can't output anything before forward.That is why u got the above error.

    -Regards
    Ramya
    You mean after forward?

  12. #12
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    843
    Rep Power
    6

    Default

    ya before forwarding,some print statements are there know? It will create problems.
    previously he tries to print something know?
    Ramya:cool:

  13. #13
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Possible solutions to this problem are
    1.) Make forward/redirect as early as possible before any HTML is output.
    2.) Increase the buffer size. <%@ page buffer="24kb"%> default is (8kb)
    3.) Put a return statement after the code
    Java Code:
    dispatcher.forward(request,response);
    But the first and most important thing is to move all the Java code away from the JSP.

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 5
    Last Post: 03-17-2011, 03:26 PM
  2. Replies: 2
    Last Post: 12-14-2009, 02:46 AM
  3. Replies: 2
    Last Post: 05-28-2009, 06:09 PM
  4. Back-Forward Simulation using stacks(java)
    By MarKus in forum New To Java
    Replies: 3
    Last Post: 09-10-2008, 02:47 PM
  5. Replies: 5
    Last Post: 07-29-2008, 03:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •