You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Raghuveer <ra...@infotechsw.com> on 2008/09/12 09:55:07 UTC

Struts 1.2.9 +Ajax Error -- java.lang.IllegalStateException

Hello,

I am using Ajax in my struts application.

 

>From JavaScript in JSP page I call "employee.do?method=employee"

 

 

I get following error

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

 

 

For Ajax calls I am using struts execute method.

But Action Forward may not be used.

 

Any suggestion for this to resolve.

I assume I get this error because of "return
mapping.findForward(strResult)";

Actual my response is already done for Ajax requests through
response.getWriter,

So struts actionforward may not be used in this scenarios.

 

 

 

 

 

public ActionForward employee(final ActionMapping mapping, final ActionForm
form, final HttpServletRequest request, final HttpServletResponse response)
{

 

      

      

      try {

 

 

sb.append("<employee>");

            sb.append("<id>100</id>");

            sb.append("<name>john</name>");

            sb.append("<email>john@sun.com</email>");

            sb.append("<phone>123123</phone>");

            sb.append("</employee >");

      

            response.setHeader("Cache-Control", "no-cache");

 

            out = response.getWriter();

            out.println(sb);

            out.flush();

            out.close();

      } catch (IOException e) {

            logger.error("IOException - "+e);

            handleException(e, CLASS_NAME, request);

            strResult=CActionPageForwards.GLOBAL_FORWARD_ACTIONERROR;   

      }finally{

            //if (out != null) {

            //    out.close();

                  //out = null;

        //}

      }

 

strResult=CActionPageForwards.FORWARD_EMPLOYEE_REQUEST;

logger.info("Result - "+strResult);

return mapping.findForward(strResult);

 

}//end execute

 


Re: Struts 1.2.9 +Ajax Error -- java.lang.IllegalStateException

Posted by Dave Newton <ne...@yahoo.com>.
Return null.


--- On Fri, 9/12/08, Raghuveer <ra...@infotechsw.com> wrote:

> From: Raghuveer <ra...@infotechsw.com>
> Subject: Struts 1.2.9 +Ajax Error -- java.lang.IllegalStateException
> To: user@struts.apache.org
> Date: Friday, September 12, 2008, 3:55 AM
> Hello,
> 
> I am using Ajax in my struts application.
> 
>  
> 
> From JavaScript in JSP page I call
> "employee.do?method=employee"
> 
>  
> 
>  
> 
> I get following error
> 
> java.lang.IllegalStateException: Cannot forward after
> response has been
> committed
> 
>  
> 
>  
> 
> For Ajax calls I am using struts execute method.
> 
> But Action Forward may not be used.
> 
>  
> 
> Any suggestion for this to resolve.
> 
> I assume I get this error because of "return
> mapping.findForward(strResult)";
> 
> Actual my response is already done for Ajax requests
> through
> response.getWriter,
> 
> So struts actionforward may not be used in this scenarios.
> 
>  
> 
>  
> 
>  
> 
>  
> 
>  
> 
> public ActionForward employee(final ActionMapping mapping,
> final ActionForm
> form, final HttpServletRequest request, final
> HttpServletResponse response)
> {
> 
>  
> 
>       
> 
>       
> 
>       try {
> 
>  
> 
>  
> 
> sb.append("<employee>");
> 
>            
> sb.append("<id>100</id>");
> 
>            
> sb.append("<name>john</name>");
> 
>            
> sb.append("<email>john@sun.com</email>");
> 
>            
> sb.append("<phone>123123</phone>");
> 
>             sb.append("</employee >");
> 
>       
> 
>             response.setHeader("Cache-Control",
> "no-cache");
> 
>  
> 
>             out = response.getWriter();
> 
>             out.println(sb);
> 
>             out.flush();
> 
>             out.close();
> 
>       } catch (IOException e) {
> 
>             logger.error("IOException - "+e);
> 
>             handleException(e, CLASS_NAME, request);
> 
>            
> strResult=CActionPageForwards.GLOBAL_FORWARD_ACTIONERROR;   
> 
>       }finally{
> 
>             //if (out != null) {
> 
>             //    out.close();
> 
>                   //out = null;
> 
>         //}
> 
>       }
> 
>  
> 
> strResult=CActionPageForwards.FORWARD_EMPLOYEE_REQUEST;
> 
> logger.info("Result - "+strResult);
> 
> return mapping.findForward(strResult);
> 
>  
> 
> }//end execute

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org