You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jason Novotny <JD...@lbl.gov> on 2001/02/12 01:11:17 UTC

errorpage.jsp: Can't convert javax.servlet.jsp.JspWriter to java.io.PrintWriter

    I've been learning JSP with this great book from manning.com and
I've been trying to write an error page. According to the book, I should
be able to do the following:


<%@ page isErrorPage="true"%>
<h1>The following error has been detected:</h1>

<b><%= exception %></b<br>

<% exception.printStackTrace(out); %>

    However, when I try this I get the following:

gpdk/_0002fjsp_0002ferror_0002ejsperror_jsp_14.java:143: Incompatible
type for method. Can't convert javax.servlet.jsp.JspWriter to
java.io.PrintWriter.
                 exception.printStackTrace(out);
                                           ^
1 error


    What's the secret to printing a stack trace to the page?

    Thanks, Jason



--
Jason Novotny               novotny@george.lbl.gov
Home: (510) 704-9917        Work: (510) 486-8662
NERSC Distributed Computing http://www-didc.lbl.gov




Re: errorpage.jsp: Can't convert javax.servlet.jsp.JspWriter to java.io.PrintWriter

Posted by William Brogden <wb...@bga.com>.

Jason Novotny wrote:
> 
>     I've been learning JSP with this great book from manning.com and
> I've been trying to write an error page. According to the book, I should
> be able to do the following:
> 
> <%@ page isErrorPage="true"%>
> <h1>The following error has been detected:</h1>
> 
> <b><%= exception %></b<br>
> 
> <% exception.printStackTrace(out); %>
> 
>     However, when I try this I get the following:
> 
> gpdk/_0002fjsp_0002ferror_0002ejsperror_jsp_14.java:143: Incompatible
> type for method. Can't convert javax.servlet.jsp.JspWriter to
> java.io.PrintWriter.
>                  exception.printStackTrace(out);
>                                            ^
> 1 error
> 
>     What's the secret to printing a stack trace to the page?

You can't cast the JspWriter to a PrintWriter so what you
have to do is create a StringWriter, use that to make a PrintWriter
and print the stack trace to it. Then just use the toString()
method of StringWriter to get a single string with the full trace.

-- 
WBB - wbrogden@lanw.com
Java Cert mock exams http://www.lanw.com/java/javacert/
Author of Java Developer's Guide to Servlets and JSP 
ISBN 0-7821-2809-2

Re: errorpage.jsp: Can't convert javax.servlet.jsp.JspWriter to java.io.PrintWriter

Posted by Chris Janicki <Ja...@ia-inc.com>.
I don't have time to test this, but I think the problem is not in the 
stack trace, but the previous line.  Try replacing it with:

<%= exception.getMessage() %>

I think the <%= %> expects a String or native.

FYI: A good way to learn/debug JSP is to look at the "*.java" file 
created by the server.  In your case, look at line 143 of 
_0002fjsp_0002ferror_0002ejsperror_jsp_14.java

>>>>>>>>>>>>>>>>>> Original Message <<<<<<<<<<<<<<<<<<

On 2/11/01, 7:11:17 PM, Jason Novotny <JD...@lbl.gov> wrote regarding 
errorpage.jsp: Can't convert javax.servlet.jsp.JspWriter to  
java.io.PrintWriter:


>     I've been learning JSP with this great book from manning.com and
> I've been trying to write an error page. According to the book, I should
> be able to do the following:


> <%@ page isErrorPage="true"%>
> <h1>The following error has been detected:</h1>

> <b><%= exception %></b<br>

> <% exception.printStackTrace(out); %>

>     However, when I try this I get the following:

> gpdk/_0002fjsp_0002ferror_0002ejsperror_jsp_14.java:143: Incompatible
> type for method. Can't convert javax.servlet.jsp.JspWriter to
> java.io.PrintWriter.
>                  exception.printStackTrace(out);
>                                            ^
> 1 error


>     What's the secret to printing a stack trace to the page?

>     Thanks, Jason



> --
> Jason Novotny               novotny@george.lbl.gov
> Home: (510) 704-9917        Work: (510) 486-8662
> NERSC Distributed Computing http://www-didc.lbl.gov




> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org

Re: errorpage.jsp: Can't convert javax.servlet.jsp.JspWriter to java.io.PrintWriter

Posted by David Wall <dw...@myEastside.com>.
> <% exception.printStackTrace(new java.io.PrintWriter(out)); %>

Just consider that this should probably only be used on a test/development
system since presenting stack traces to site visitors is probably not a
grand idea.

David


Re: errorpage.jsp: Can't convert javax.servlet.jsp.JspWriter to java.io.PrintWriter

Posted by Gilles Laborderie <gx...@careersite.com>.
The error message tells you that it's trying to convert "out" from
JspWriter to a PrintWriter which is the type expected from
printStackTrace.


Try:

<% exception.printStackTrace(new java.io.PrintWriter(out)); %>

This will creates a new PrintWriter from the existing "out"

Gilles

On Sun, 11 Feb 2001, Jason Novotny wrote:

>
>     I've been learning JSP with this great book from manning.com and
> I've been trying to write an error page. According to the book, I should
> be able to do the following:
>
>
> <%@ page isErrorPage="true"%>
> <h1>The following error has been detected:</h1>
>
> <b><%= exception %></b<br>
>
> <% exception.printStackTrace(out); %>
>
>     However, when I try this I get the following:
>
> gpdk/_0002fjsp_0002ferror_0002ejsperror_jsp_14.java:143: Incompatible
> type for method. Can't convert javax.servlet.jsp.JspWriter to
> java.io.PrintWriter.
>                  exception.printStackTrace(out);
>                                            ^
> 1 error
>
>
>     What's the secret to printing a stack trace to the page?
>
>     Thanks, Jason
>
>
>
> --
> Jason Novotny               novotny@george.lbl.gov
> Home: (510) 704-9917        Work: (510) 486-8662
> NERSC Distributed Computing http://www-didc.lbl.gov
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, email: tomcat-user-help@jakarta.apache.org
>

-- 
Gilles Laborderie
---------------------------------------------
CareerSite.com
gxl@careersite.com