tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrey Akselrod" <aaksel...@runtime.com>
Subject RE: IllegalStateException - tomcat 4
Date Thu, 15 Feb 2001 20:44:24 GMT
Craig, Michael,

thank you for your help!

Craig, your last email explained everything - thank you. I am a lot less
stressed now :) I have a few questions though.

Instead of mapping each servlet I just removed /servlet/* invoker mapping.
It worked after that. Is it safe to do so? What does the invoker do?
I took a look at the source code - and realized that you wrote it! Thanks
for taking your time to explain it all...
Anyway, why do you forward instead of include in there? How come Tomcat
works without this association (/servlet/*)?

Thank you again,
-a


> -----Original Message-----
> From: Craig R. McClanahan [mailto:Craig.McClanahan@eng.sun.com]
> Sent: Thursday, February 15, 2001 2:30 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Re: IllegalStateException - tomcat 4
>
>
> The reason you are getting the exeption is that the invoker
> servlet (the one mapped to
> "/servlet/*" does a RequestDispatcher.forward() to call the
> actual servlet class.
> Thus, you are getting the error because you did the flush() in
> the JSP page before
> calling.  NOTE:  The existence of an invoker servlet is a Tomcat
> feature, and is not
> part of the spec, so there are no rules about how they work.
>
> To avoid this problem, you should set up a <servlet-mapping>
> entry in your web.xml file
> so that you can do a request dispatcher directly to your servlet
> itself.  For example,
> if you have the following entries in web.xml:
>
>     <servlet>
>         <servlet-name>MyServlet</servlet-name>
>         <servlet-class>includetest.secondservlet</servlet-class>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>MyServlet</servlet-name>
>         <url-pattern>/include-test</url-pattern>
>     </servlet-mapping>
>
> Then you can call your dispatcher like this:
>
>     <%
>         out.flush();
>         RequestDispatcher rd =
> request.getRequestDispatcher("/include-test");
>         rd.include(request, response);
>     %>
>
> or, even simpler:
>
>     <jsp:include page="/include-test" flush="true"/>
>
> Craig McClanahan
>
> PS:  Removing the flush() in your calling page would also make
> the original example
> work correctly :-).
>
>
>
>
> Andrey Akselrod wrote:
>
> > Hello,
> >
> > I have searched archives and have seen similar discussions, but
> could not
> > really find an answer.
> > I am developing a software on top of Servlet API 2.3 so I do need to use
> > Tomcat at least for now. I tried to create a very simplified
> test case. I
> > was able to reproduce a part of the problem so far, so that I can move
> > forward.
> > I am getting the following exception:
> >
> > java.lang.IllegalStateException: Cannot forward after response has been
> > committed
> >         at
> >
> org.apache.catalina.core.ApplicationDispatcher.doForward(Applicati
> onDispatch
> > er.java:245)
> >         at
> >
> org.apache.catalina.core.ApplicationDispatcher.forward(Application
> Dispatcher
> > .java:236)
> >         at
> >
> org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerSe
> rvlet.java
> > :386)
> >         at
> >
> org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:144)
> >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
> >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> >         at
> >
> org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationD
> ispatcher.
> > java:573)
> >         at
> >
> org.apache.catalina.core.ApplicationDispatcher.doInclude(Applicati
> onDispatch
> > er.java:483)
> >         at
> >
> org.apache.catalina.core.ApplicationDispatcher.include(Application
> Dispatcher
> > .java:388)
> >         at
> >
> _0002ffirst_0002ejspfirst_jsp_28._jspService(_0002ffirst_0002ejspf
> irst_jsp_2
> > 8.java:57)
> >         at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
> >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> >         at
> >
> org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(Jsp
> Servlet.ja
> > va:184)
> >         at
> org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:328)
> >         at
> org.apache.jasper.servlet.JspServlet.service(JspServlet.java:407)
> >         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> >         at
> >
> org.apache.catalina.core.ApplicationFilterChain.doFilter(Applicati
> onFilterCh
> > ain.java:215)
> >         at
> >
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapp
> erValve.ja
> > va:251)
> >         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
> >         at
> >
> org.apache.catalina.core.StandardContextValve.invoke(StandardConte
> xtValve.ja
> > va:196)
> >         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
> >         at
> >
> org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2041)
> >         at
> >
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValv
> e.java:161
> > )
> >         at
> org.apache.catalina.valves.ValveBase.invokeNext(ValveBase.java:242)
> >         at
> >
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:414)
> >         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:975)
> >         at
> >
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngine
> Valve.java
> > :159)
> >         at
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:977)
> >         at
> >
> org.apache.catalina.connector.http.HttpProcessor.process(HttpProce
> ssor.java:
> > 818)
> >         at
> >
> org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor
> .java:897)
> >         at java.lang.Thread.run(Thread.java:484)
> >
> > This problem happens when I try to include a servlet from a jsp page:
> > <H1>First JSP</H1>
> > <%
> > out.flush();
> > //RequestDispatcher d = request.getRequestDispatcher("/second.jsp");
> > RequestDispatcher d =
> > request.getRequestDispatcher("/servlet/includetest.secondservlet");
> > d.include(request, response);
> > %>
> >
> > The servlet itself can be empty or can simply print out something with:
> > resp.getWriter().println("look ma, i am here.");
> >
> > If I try to include /second.jsp - it works without the
> exception. It fails
> > only for the servlet.
> > By "failing" I mean that it generates an exception in the log
> the first time
> > I try to execute my jsp file after Tomcat was restarted. After
> that it just
> > works fine.
> > It also works if I remove "flush()" - but then the output of the servlet
> > comes before the output of jsp file.
> > Another interesting thing: the test case works in ServletExcec.
> >
> > I read the spec - it says that there are limitations with "forward", but
> > "include" should be just fine.
> > Another question is if you take a look at the stack - it calls
> "include" and
> > after that it calls "forward" where it fails - any idea why?
> >
> > Thank you,
> >
> > Andrey Akselrod, Senior Software Architect
> > aakselrod@runtime.com
> > ======================================================================
> > RUNTIME TECHNOLOGIES                                  www.runtime.com
> > 515 Greenwich Street, 2nd Floor                   T.212.462.2800.X.104
> > New York, New York 10013                                F.212.462.1074
> > ======================================================================
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, email: tomcat-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org
>
>


Mime
View raw message