Elisabeth,
Tomcat will compile your jsp page converting *any* HTML element into an
out.println("<something>");
So, if you don't write any HTML in yor servlet you can do what you want.
The point is that problem is using the printwriter, not opening it. I
tested this idea and created a jsp page that contains NO html at all, it
looks like:
<%out.close()%>
and thats it, (even without a CRLF at the end of the line).
It seems to work OK, nothing is output to the printwriter. I believe you can
replace the line I wrote with your redirection, and that should work fine.
Hope it helps..
Julio Serje
Calian Tech.
Ottawa, Canada
P.S. The complete java servlet that is generated from that jsp is :
package jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.Vector;
import org.apache.jasper.runtime.*;
import java.beans.*;
import org.apache.jasper.JasperException;
public class _0002fjsp_0002fno_0005fout_0002ejspno_0005fout_jsp_0 extends
HttpJspBase {
static {
}
public _0002fjsp_0002fno_0005fout_0002ejspno_0005fout_jsp_0( ) {
}
private static boolean _jspx_inited = false;
public final void _jspx_init() throws JasperException {
}
public void _jspService(HttpServletRequest request, HttpServletResponse
response)
throws IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
String _value = null;
try {
if (_jspx_inited == false) {
_jspx_init();
_jspx_inited = true;
}
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html;charset=8859_1");
pageContext = _jspxFactory.getPageContext(this, request,
response,
"", true, 8192, true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
// begin [file="C:\\jsp\\no_out.jsp";from=(0,2);to=(0,15)]
out.close();
// end
} catch (Exception ex) {
if (out.getBufferSize() != 0)
out.clearBuffer();
pageContext.handlePageException(ex);
} finally {
out.flush();
_jspxFactory.releasePageContext(pageContext);
}
}
}
----- Original Message -----
From: Elisabeth Freeman <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, October 25, 2000 1:37 PM
Subject: RE: tomcat-user Digest 24 Oct 2000 20:53:09 -0000 Issue 293
> I agree, doing this with a servlet is the right way to go. However,
because
> this is already in production, it would be much simpler to change the jsp
> than add a servlet at this point (which would require QA, updating the
> server properties, etc.).
>
> I have searched everywhere and can't find anything about telling tomcat
not
> to open the print writer. I'm assuming it can't be done, however, if this
> is wrong, please let me know.
>
> Thanks.
>
> Elisabeth Freeman
>
> -----Original Message-----
> Date: Tue, 24 Oct 2000 14:27:43 -0500
> To: [EMAIL PROTECTED]
> From: William Brogden <[EMAIL PROTECTED]>
> Subject: Re: help with generated servlet and IllegalStateException
> Message-ID: <[EMAIL PROTECTED]>
>
> Elisabeth Freeman wrote:
> >
> > Hi,
> > I have noticed that the servlets being generated from my JSPs *always*
> grap
> > the PrintWriter "out", even if I am not using it in my JSP. This causes
> > serious problems when I want to redirect - I get an
IllegalStateException
> > which seems to hang the thread in my application, so after a few hundred
> > hits, the application is dying (on Windows NT, doens't seem to happen on
> > Windows 2K). Is there any way for me to direct Jasper *not* to get the
> > print writer at all in the generated servlet?
> >
> > Thanks!!!
> >
> > Elisabeth Freeman
>
> If you are not going to be writing any HTML, why bother with JSP?
> Why not do whatever it is you are doing with a servlet?
>
> --
> WBB - [EMAIL PROTECTED] Chief Scientist, LANWrights, Inc.
> Java Programmer Certification information and mock exam
> at http://www.lanw.com/java/javacert/
>
> ------------------------------
>
>