6.1 SP5: response.sendRedirect crashes

Hi all,

I am porting a JSP app from Iplanet 4.1 to SunONE 6.1 SP5 (Solaris 5.9).

When I try to do the above statement in a JSP, I get the following in the error log:

[14/Jun/2007:16:05:05] failure ( 3812): for host 172.16.10.184 trying to POST /jspcontent/ozbet.jsp;jsessionid=43DBC3EA6343C4B0E3BF6AD26B943D25, service-j2ee reports: StandardWrapperValve[jsp]: WEB2792: Servlet.service() for servlet jsp threw exception

java.lang.IllegalStateException

at org.apache.catalina.connector.HttpResponseFacade.sendRedirect(HttpResponseFacad e.java:179)

at _jsps._jspcontent._ozbet_jsp._jspService(_ozbet_jsp.java:109)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:908)

at com.iplanet.ias.web.jsp.JspServlet$JspServletWrapper.service(JspServlet.java:68 7)

at com.iplanet.ias.web.jsp.JspServlet.serviceJspFile(JspServlet.java:459)

at com.iplanet.ias.web.jsp.JspServlet.service(JspServlet.java:375)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:908)

at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrap perValve.java:771)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 322)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java: 212)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:209)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)

at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java: 161)

at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)

I am not sure what I need to declare differently in 6.1. The web app jars are in WEB-INF/lib under the docroot.

The code in the JSP is pretty standard, but ran under Iplanet 4.1.

try {

String URL = "https://www.ozbet.com.au/tab/ozbet.htm?p_date=" //has parameters;

response.sendRedirect(URL);

}

catch (ApplicationException e) {

//do some stuff here

%>

<b>ERROR:</b> <%= msg %>"

<%

}

FYI the webapp is working fine wrt to jdbc, jsp etc. It is just the sendRedirect() that is crashing.

Do I need to declare anything related to NSAPI in obj.conf ?

Please help and thanks in advance.

Richard

Message was edited by:

r_defonseka

Message was edited by:

r_defonseka

[2724 byte] By [r_defonsekaa] at [2007-11-27 7:39:05]
# 1
Have you tried this on latest SP: 6.1 SP7?
scandya at 2007-7-12 19:19:42 > top of Java-index,Web & Directory Servers,Web Servers...
# 2

That's not a crash. HttpServletResponse.sendRedirect is throwing an IllegalStateException because you called it after the response had been committed. This is a documented part of the Servlet spec. (See, for example, http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRes ponse.html#sendRedirect(java.lang.String) for the the J2EE 1.3 docs.)

The most likely problem is that you're calling sendRedirect after an include or after outputting too much data. If you're going to call sendRedirect, you need to do so near the top of your JSP file, before you output a lot of data. Once data has been sent to the client, there's no way for the server to say "oops, never mind, ignore that data and redirect over here instead".

elvinga at 2007-7-12 19:19:42 > top of Java-index,Web & Directory Servers,Web Servers...
# 3

Thank you for your replies all.

I have upgraded to SP7: still getting the error message.

BTW the jsp file is mostly scriptlet and has very little HTML embedded (is this what elving means by 'populating too much data' ?). The calling code is minimal as well, although I will check this out to see if the "response" object is being used prior to the redirect.

I repeat that the code did run under Iplanet 4.1, but probably under an earlier jdk/j2eesdk.

Could this be significant ?

Regards,

Richard

r_defonsekaa at 2007-7-12 19:19:42 > top of Java-index,Web & Directory Servers,Web Servers...
# 4
I tweaked the buffer directive, from<%@ page buffer="none"%>to <%@ page buffer="8"%>based on your hints about commiting/flushing the output.Some testing to be done now, no other coding changes.Was this ok to do ?Thanks again :)
r_defonsekaa at 2007-7-12 19:19:42 > top of Java-index,Web & Directory Servers,Web Servers...
# 5
Unless you have a good reason not to, you should allow the server to use its default buffer size. To do that, remove the <%@ page buffer="none"%> directive altogether.
elvinga at 2007-7-12 19:19:42 > top of Java-index,Web & Directory Servers,Web Servers...
# 6
> Unless you have a good reason not to, you should> allow the server to use its default buffer size. To> do that, remove the <%@ page buffer="none"%>> directive altogether.Thank you so much!And have a good weekend :)
r_defonsekaa at 2007-7-12 19:19:42 > top of Java-index,Web & Directory Servers,Web Servers...