Reputation: 981
I'm using Apache 2.2 and Tomcat 6.0.18 on Windows XP. I've enabled the mod_proxy module to redirect the traffic from my Apache web server to Tomcat. I only updated the httpd.conf file to have the redirection like this:
ProxyPass /myapp http://MYMACHINENAME:8080/MyApp/Start
ProxyPassReverse /myapp http://MYMACHINENAME:8080/MyApp/Start
The problem I'm experiencing is that the initial redirect works fine, the JSP page renders correctly. When I try to navigate to a different JSP page by clicking on a menu on the page, I get the exception:
SEVERE: Servlet.service() for servlet StartIntro threw exception
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
at StartIntro.doPost(StartIntro.java:103)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
If I don't do any redirection from Apache, the navigation works fine.
Any ideas what I should look into?
TIA, Magnus Lassi
Upvotes: 2
Views: 18685
Reputation: 11
You have commited your Response and then probably you are writing Data to JSP might be through List or JSON. If you are redirecting to the Same JSP and you are returning STRING as "success" then this exception occurs.Because Returning SUCCESS through STRUTS@ commits Your Response and it would not allow to post any further data to your JSP.
Solution : All you need to do is RETURN NULL and Redirect to same JSP page.. Hope It helps You
Upvotes: 0
Reputation: 6342
Use AJP Proxy, that is supported by Apache 2.2 and Tomcat 6.0.18.
You'll need to install mod_proxy_ajp for apache if it isn't installed already, and make sure tomcat is configured to listen for ajp connections (check server.xml).
By default Tomcat 6.0.18 listens for AJP connections in port 8009.
Then you need to add something like this in your httpd.conf
<Proxy *>
AddDefaultCharset Off
Order deny,allow
Allow from all
</Proxy>
ProxyPass /yoururl ajp://ip.for.tomcat.server:8009/yoururl
ProxyPassReverse /yoururl ajp://ip.for.tomcat.server:8009/yoururl
Then you can go to http://apachehost/yoururl and all redirection should be made transparent. Furthermore it is more efficient that html proxy because ajp is a more low level protocol.
Upvotes: 0
Reputation: 1109132
Although this is an old topic which was been poked by community, I'll post my thoughts:
java.lang.IllegalStateException
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
at StartIntro.doPost(StartIntro.java:103)
This can happen if something in StartIntro#doPost()
has already committed the response. A response is commited when one of the following cases is met:
forward()
or include()
has been invoked on the same response before.flush()
is invoked.I would doublecheck what the StartIntro#doPost()
is all doing. The mentioned 2KB is appserver-dependent though, in case of Tomcat it's configureable as buffer size of the HTTP connector.
I would add, a common mistake among starters is that they think that the call of a forward()
or a sendRedirect()
would magically exit and "jump" out of the method block, hereby ignoring the remnant of the code. For example:
protected void doPost() {
if (someCondition) {
forward();
}
redirect(); // This is STILL invoked when someCondition is true!
}
This is thus actually not true. To fix this you would need to add a return;
statement to the end of the if
block, or to introduce an else
block for the redirect()
call.
Hope this information helps in nailing down the root cause.
Upvotes: 13
Reputation: 30448
You can use the ProxySet directive:
ProxySet ajp://mymachine:7001 <parameters>
See more at the Apache Documentation
Upvotes: 0