• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IllegalStateException error come on servlet side

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello firends,
when i write the code which refresh the jsp page automatically, at a time following error is come on servlet side..

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

And in the servlet error line is

request.getRequestDispatcher("/jspusermgmtListCamera.jsp").forward(request,response);

And my servlet code is like this

public void execute(HttpServletRequest request,HttpServletResponse response){
System.out.println("Inside execute method of ListCameraAction");
try{
ResultObject resultObject = new ResultObject(MReporterResponceCode.UNKNOWN_ERROR_CODE,null);
String pagesize = request.getParameter("cmbPageSize");
String start = request.getParameter("start");
log.debug("Start : " + start);

session = request.getSession(false);
activityLog logdb = (activityLog)session.getAttribute("ActivityLog");
if(logdb == null){
logdb = new activityLog("WEB");
}
logdb.InsertAction("ListCameras");
UserDAO userDAO=null;
logdb.InsertActionDetails("INFO", "List", "List All Cameras");
userDAO = (UserDAO)session.getAttribute(MReporterConstant.USERDAO_OBJECT);
if(userDAO!=null){
logID =Integer.toString(userDAO.getUserId());
}
request.setAttribute("USERID",logID);
resultObject = getUserCamera(request,response);
if(resultObject.getResponseCode()!=null && resultObject.getResponseCode().trim().equalsIgnoreCase(MReporterResponceCode.SUCCESS_RESPONSE_CODE)){
if(pagesize == null){
//pagesize = Integer.toString(((Collection)resultObject.getResponseObject()).size());
pagesize = Integer.toString(MReporterConstant.PAGE_SIZE);

}
log.debug("Page Size :: " + pagesize);
request.setAttribute("cameraList",(Collection)resultObject.getResponseObject());
request.setAttribute("pageSize",pagesize);
request.setAttribute("start",start);
request.getRequestDispatcher("/jsp/usermgmt/ListCamera.jsp").forward(request,response);
}else{
log.error("Not a success response code " + resultObject);
}
//String logID = (String)session.getAttribute("logID");
if(logID != null){
WebAccessLogDAO accessLog = WebAccessLogDAO.getWebAccessLog(Integer.parseInt(logID));
accessLog.setTranscript(logdb.getLog());
accessLog.upDate();
}
session.setAttribute("ActivityLog", logdb);
log.debug(" Out from try---------------------------------------------");
}catch(Exception ex){
log.error("Exception in ListUsersAction:execute() method " + ex);
ex.printStackTrace();
}//end try-catch
log.debug("Out from execute method of ListUsersAction");
}

any one give me solution....

Regards
Devarshi
 
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The exception says: You have started writing into the response object and then you try to forward request to another JSP file.

Make sure there you don't write any thing to response object (out.write or out.println) before you forward.


One more thing, did you paste the code of same servlet? because I don't see the line request.getRequestDispatcher("/jspusermgmtListCamera.jsp").forward(request,response); in servlet.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
RequestDispatcher does not help your control by exiting from the servlet (it does NOT exit from the servlet and return the control back to the point of invocation). Since, you are not writing anything to the response object, the ideal solution is to 'return' after forward has been executed.
[ December 15, 2008: Message edited by: Nitin Pathak ]
 
Nitin Pathak
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not aware whether you managed to solve your problem, but here is JavaRanch faq for your beloved exception.

Hope this would make things clearer!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic