Re: IllegalStateException: Cannot forward. Response already committed.

2009-05-24 Thread Wes Wannemacher
Try turning the page buffer up really high... Like 256k or something 
obnoxious. It's obviously not a real solution, but it might get you by if 
you're on a deadline. I would try firing up a debugger and see what is 
generating the output. Another solution would be to try a different app 
server. If you're running in Tomcat, try Jetty to see if that helps you narrow 
down the issue. 

-Wes

On Thursday 21 May 2009 09:57:20 am Hermann X Lau wrote:
> Hi,
>
> I tried out your suggestions and I am still getting this exception.  I even
> put everything in the JSP in one line and mad sure there were no
> whitespaces.
>
> <%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic"%><%@
> page contentType="text/html" import="org.apache.log4j.Logger"%><%final
> Logger log =
> Logger.getLogger("index.jsp");log.debug("begin");%> name="welcome" />
>
> Any other ideas?
>
> -Original Message-
> From: Wes Wannemacher [mailto:w...@wantii.com]
> Sent: Wednesday, May 20, 2009 4:48 PM
> To: Struts Users Mailing List
> Subject: Re: IllegalStateException: Cannot forward. Response already
> committed.
>
> The JSP compiler simple turns those <% %> tags inside out and
> everything outside of those tags is a string with an out.print... In
> your case, the first two things in the file generate returns...
> Whitespace is significant... Let me see if I can make it visually more
> understandable
>
> Index.jsp
> <%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic"%>
> < RIGHT HERE, You will get a out.print("\n");
> <%@ page contentType="text/html" import="org.apache.log4j.Logger"%>
> <- SAME HERE
> <%
>
> Hopefully it doesn't get all wrapped and screwed up.
>
> You might be wondering now, why does it work sometimes and not
> others... Well, the IllegalStateException is only thrown if output has
> been flushed, so you can get away with breaking the rules from time to
> time. You can even set the page buffer variable really high so that
> you reserve the right to redirect, even if you have generated some
> output.
>
> Anyhow, try to remove whitespace, you could probably just do it this
> way and have it work -
> Index.jsp ->
> <%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic" %><%@
>page contentType="text/html" import="org.apache.log4j.Logger"
> %><%
> final Logger log = Logger.getLogger("index.jsp");
> log.debug("begin");
>  %>
>
>
> On Wed, May 20, 2009 at 4:39 PM, Hermann X Lau
>
>  wrote:
> > Thanks in advance for any help on this...
> >
> >  I understand we get this exception when the JSP attempts to write to the
> > print stream after the response has been committed but I don't see how
> > this is occurring in my situation since my JSP just contains a simple
> > forward.
> >
> > Index.jsp
> > <%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic"%>
> > <%@ page contentType="text/html" import="org.apache.log4j.Logger"%>
> > <%
> >final Logger log = Logger.getLogger("index.jsp");
> >log.debug("begin");
> > %>
> > 
> >
> > Here is my action class (note that in my logs, this exception occurs even
> > before the execute method is called!): public class ChoiceAction extends
> > StrutsAction {
> >
> >public ActionForward execute(ActionMapping mapping,
> > ActionForm form, HttpServletRequest request, HttpServletResponse
> > response) throws Exception { log4j.debug("execute");
> >ManifestChoiceFormBean choiceForm =
> > (ManifestChoiceFormBean) form; Connection conn =
> > DAOUtils.getConnection("jdbc/OSURptDb");
> >
> >try {
> >RenderRequest req =
> > (RenderRequest)request.getAttribute("javax.portlet.request"); String
> > sites = getResources(request).getMessage("upsws.site.list." +
> > req.getPreferences().getValue("SITE_IND","").toLowerCase());
> > log4j.debug(sites); IMailManifestDAO dao =
> > DAOBuilder.buildMailManifestDAO(conn); boolean uspsActive =
> > dao.uspsJobsExist(sites); choiceForm.setUspsActive(uspsActive);
> > log4j.info("USPS link is " + ((uspsActive) ? &

RE: IllegalStateException: Cannot forward. Response already committed.

2009-05-21 Thread Hermann X Lau
Hi,

I tried out your suggestions and I am still getting this exception.  I even put 
everything in the JSP in one line and mad sure there were no whitespaces.

<%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic"%><%@ page 
contentType="text/html" import="org.apache.log4j.Logger"%><%final Logger log = 
Logger.getLogger("index.jsp");log.debug("begin");%>

Any other ideas?

-Original Message-
From: Wes Wannemacher [mailto:w...@wantii.com] 
Sent: Wednesday, May 20, 2009 4:48 PM
To: Struts Users Mailing List
Subject: Re: IllegalStateException: Cannot forward. Response already committed.

The JSP compiler simple turns those <% %> tags inside out and
everything outside of those tags is a string with an out.print... In
your case, the first two things in the file generate returns...
Whitespace is significant... Let me see if I can make it visually more
understandable

Index.jsp
<%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic"%>
< RIGHT HERE, You will get a out.print("\n");
<%@ page contentType="text/html" import="org.apache.log4j.Logger"%>
<- SAME HERE
<%

Hopefully it doesn't get all wrapped and screwed up.

You might be wondering now, why does it work sometimes and not
others... Well, the IllegalStateException is only thrown if output has
been flushed, so you can get away with breaking the rules from time to
time. You can even set the page buffer variable really high so that
you reserve the right to redirect, even if you have generated some
output.

Anyhow, try to remove whitespace, you could probably just do it this
way and have it work -
Index.jsp ->
<%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic" %><%@
   page contentType="text/html" import="org.apache.log4j.Logger"
%><%
final Logger log = Logger.getLogger("index.jsp");
log.debug("begin");
 %>


On Wed, May 20, 2009 at 4:39 PM, Hermann X Lau
 wrote:
> Thanks in advance for any help on this...
>
>  I understand we get this exception when the JSP attempts to write to the 
> print stream after the response has been committed but I don't see how this 
> is occurring in my situation since my JSP just contains a simple forward.
>
> Index.jsp
> <%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic"%>
> <%@ page contentType="text/html" import="org.apache.log4j.Logger"%>
> <%
>                final Logger log = Logger.getLogger("index.jsp");
>                log.debug("begin");
> %>
> 
>
> Here is my action class (note that in my logs, this exception occurs even 
> before the execute method is called!):
>                 public class ChoiceAction extends StrutsAction {
>
>                public ActionForward execute(ActionMapping mapping, ActionForm 
> form, HttpServletRequest request, HttpServletResponse response) throws 
> Exception {
>                                log4j.debug("execute");
>                                ManifestChoiceFormBean choiceForm = 
> (ManifestChoiceFormBean) form;
>                                Connection conn = 
> DAOUtils.getConnection("jdbc/OSURptDb");
>
>                                try {
>                                                RenderRequest req = 
> (RenderRequest)request.getAttribute("javax.portlet.request");
>                                                String sites = 
> getResources(request).getMessage("upsws.site.list." + 
> req.getPreferences().getValue("SITE_IND","").toLowerCase());
>                                                log4j.debug(sites);
>                                                IMailManifestDAO dao = 
> DAOBuilder.buildMailManifestDAO(conn);
>                                                boolean uspsActive = 
> dao.uspsJobsExist(sites);
>                                                
> choiceForm.setUspsActive(uspsActive);
>                                                log4j.info("USPS link is " + 
> ((uspsActive) ? " active": " not active"));
>
>                                                return 
> mapping.findForward("next");
>
>                                } finally {
>                                                DAOUtils.closeConnection(conn);
>                                }
>                }
>                static final Logger log4j = 
> Logger.getLogger(ChoiceAction.class);
> }
>
> log:
> INFO : 2009-05-20 16:26:18,581 
> com.bbb.a

Re: IllegalStateException: Cannot forward. Response already committed.

2009-05-20 Thread Dale Newfield
Sorry to hijack this thread, but it looks like Wes has already given you 
a pretty complete answer.


At first I thought you were going to be asking about this:
http://wiki.glassfish.java.net/Wiki.jsp?page=FaqWebAppUnableToSetRequestCharEncoding

I get a warning in my glassfish logs for pretty much every request, and 
while I've not spent time to track this down I was hoping someone else 
here might have figured this one out already.


I see that in the prepare method of 
org.apache.struts2.dispatcher.Dispatcher it calls setCharacterEncoding 
on the request, so that does seem pretty early in the process...
...so either that's not getting called or something else is also trying 
to set this later and that's the source of my problems?


-Dale

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



Re: IllegalStateException: Cannot forward. Response already committed.

2009-05-20 Thread Wes Wannemacher
The JSP compiler simple turns those <% %> tags inside out and
everything outside of those tags is a string with an out.print... In
your case, the first two things in the file generate returns...
Whitespace is significant... Let me see if I can make it visually more
understandable

Index.jsp
<%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic"%>
< RIGHT HERE, You will get a out.print("\n");
<%@ page contentType="text/html" import="org.apache.log4j.Logger"%>
<- SAME HERE
<%

Hopefully it doesn't get all wrapped and screwed up.

You might be wondering now, why does it work sometimes and not
others... Well, the IllegalStateException is only thrown if output has
been flushed, so you can get away with breaking the rules from time to
time. You can even set the page buffer variable really high so that
you reserve the right to redirect, even if you have generated some
output.

Anyhow, try to remove whitespace, you could probably just do it this
way and have it work -
Index.jsp ->
<%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic" %><%@
   page contentType="text/html" import="org.apache.log4j.Logger"
%><%
final Logger log = Logger.getLogger("index.jsp");
log.debug("begin");
 %>


On Wed, May 20, 2009 at 4:39 PM, Hermann X Lau
 wrote:
> Thanks in advance for any help on this...
>
>  I understand we get this exception when the JSP attempts to write to the 
> print stream after the response has been committed but I don't see how this 
> is occurring in my situation since my JSP just contains a simple forward.
>
> Index.jsp
> <%@ taglib uri="http://struts.apache.org/tags-logic"; prefix="logic"%>
> <%@ page contentType="text/html" import="org.apache.log4j.Logger"%>
> <%
>                final Logger log = Logger.getLogger("index.jsp");
>                log.debug("begin");
> %>
> 
>
> Here is my action class (note that in my logs, this exception occurs even 
> before the execute method is called!):
>                 public class ChoiceAction extends StrutsAction {
>
>                public ActionForward execute(ActionMapping mapping, ActionForm 
> form, HttpServletRequest request, HttpServletResponse response) throws 
> Exception {
>                                log4j.debug("execute");
>                                ManifestChoiceFormBean choiceForm = 
> (ManifestChoiceFormBean) form;
>                                Connection conn = 
> DAOUtils.getConnection("jdbc/OSURptDb");
>
>                                try {
>                                                RenderRequest req = 
> (RenderRequest)request.getAttribute("javax.portlet.request");
>                                                String sites = 
> getResources(request).getMessage("upsws.site.list." + 
> req.getPreferences().getValue("SITE_IND","").toLowerCase());
>                                                log4j.debug(sites);
>                                                IMailManifestDAO dao = 
> DAOBuilder.buildMailManifestDAO(conn);
>                                                boolean uspsActive = 
> dao.uspsJobsExist(sites);
>                                                
> choiceForm.setUspsActive(uspsActive);
>                                                log4j.info("USPS link is " + 
> ((uspsActive) ? " active": " not active"));
>
>                                                return 
> mapping.findForward("next");
>
>                                } finally {
>                                                DAOUtils.closeConnection(conn);
>                                }
>                }
>                static final Logger log4j = 
> Logger.getLogger(ChoiceAction.class);
> }
>
> log:
> INFO : 2009-05-20 16:26:18,581 
> com.bbb.adf.controller.WpsStrutsPortletOSU:WpsStrutsPortletOSU init() using 
> URL = file:/usr/WebSphere/wps61/wp_profile/installedApps/ret7a15
> 9/PA_MailManifest.ear/MailManifest.war/WEB-INF/classes/log4j.properties
> DEBUG: 2009-05-20 16:26:19,264 index.jsp:begin
> ERROR: 2009-05-20 16:26:19,713 com.bbb.exceptions.DefaultHandler:Exception 
> caught by default handler.
> javax.portlet.PortletException: javax.portlet.PortletException: 
> javax.servlet.jsp.JspException: Exception forwarding for name welcome: 
> java.lang.IllegalStateException: Cannot
> forward. Response already committed.
>        at 
> com.ibm.portal.struts.command.StrutsViewJspCommand.includeURL(StrutsViewJspCommand.java:192)
>        at 
> com.ibm.portal.struts.command.StrutsViewJspCommand.execute(StrutsViewJspCommand.java:154)
> 
> Caused by:
> javax.portlet.PortletException: javax.servlet.jsp.JspException: Exception 
> forwarding for name welcome: java.lang.IllegalStateException: Cannot forward. 
> Response already commit
> ted.
>        at 
> com.ibm.ws.portletcontainer.core.impl.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:125)
>        at 
> com.ibm.ws.portletcontainer.core.impl.PortletRequestDispatcherImpl.include(Portl