jsp - Getting exception saying Cannot forward after response has been committed -
hi using simple forward method getting following exception
java.lang.illegalstateexception: cannot forward after response has been committed. i know exception occurs if try forward after sendredirect() in case simple forward still getting exception. interesting part code works when 2nd if true. is,
if(strcoyoterequest.contains("buildnplay")) this works fine.
but not work on other conditions.
following code
string strforwardpage = new string(); string strquerystring = request.getquerystring(); string strcoyoterequest = request.getrequesturi(); if(strcoyoterequest.contains("adminconsole")) strforwardpage = "/adminconsole/index.jsp"; else if(strcoyoterequest.contains("buildnplay")) strforwardpage = "/buildnplay/index.jsp"; else if(strcoyoterequest.contains("portal")) strforwardpage = "/portal/index.jsp"; else if(strcoyoterequest.contains("servicedashboard")) strforwardpage = "/servicedashboard/index.jsp"; requestdispatcher dispatcher = request.getrequestdispatcher(strforwardpage); response.setheader("cache-control", "no-cache"); response.setheader("pragma", "no-cache"); dispatcher.forward(request, response);
don't call response.setheader(...); before forwarding. that's committing response.
the page being forwarded 1 cache-control in.
Comments
Post a Comment