[ Team LiB ] Previous Section Next Section

Q&A

Q1:

Why do I get compile errors on the line with my page directive?

A1:

The most likely cause of this problem is that you put a space between the <% and the @. The <%@ tag used for JSP directives is not the same as the <% tag. When you put a space in there, the JSP compiler thinks you want the <% tag, and the @ symbol becomes part of the Java code within the <% tag.

Q2:

Why doesn't my import work?

A2:

Did you remember the .* at the end? Programmers often mean to import java.util.* or java.sql.* and forget the .* at the end. Make sure you don't put a ";" after the import as you do in a normal java class.

Q3:

Why do I get an exception when I go to an error page?

A3:

You probably have already committed the output buffer (sent it to the browser). When you go to an error page, the JSP engine attempts to clear the output buffer so that the error page doesn't contain a mixture of the original page and the error page. This problem occurs most often when you have included another page or forwarded to another page. If you must include or forward, try moving the code that throws the exception as close to the top of the page as you can so you handle any exceptions before you commit the buffer.

Q4:

Why do I see part of the original page before the error page?

A4:

You have most likely already committed the output buffer, but your JSP engine doesn't throw an exception when you try to hit the error page. Some JSP engines will not let you forward to the error page after output has been sent to the browser. Others don't care, but you see part of the original page. Again, try to do things that can throw an exception as early as possible.

Q5:

I specified an alternate superclass; why won't my JSP compile?

A5:

Are you sure that the superclass is in the classpath? Usually you just put the superclass in the WEB-INF/classes directory of your Web application.

Q6:

My JSP compiles; why do I get a runtime error when the page executes?

A6:

Make sure your superclass is really a servlet and that it implements the HttpJspPage interface. Depending on the JSP engine, the JSP might compile even if the class doesn't implement HttpJspPage, but when the JSP engine goes to load the JSP's servlet, it sees that the superclass isn't a JSP servlet because it doesn't implement HttpJspPage.


    [ Team LiB ] Previous Section Next Section