[ Team LiB ] Previous Section Next Section



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


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.


Why doesn't my import work?


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.


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


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.


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


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.


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


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.


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


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