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>[EMAIL PROTECTED]</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

 

Reply via email to