I ran across a problem while trying to learn how to program with tomcat/jsp.

I was running a simple case statement and got an error stating "Statement
not reached".
=============================
Error: 500
Location: /lucas/switch.jsp
Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for
JSPC:\bin\tomcat\3.2.3\work\localhost_8080%2Flucas\_0002fswitch_0002ejspswit
ch_jsp_3.java:74: Statement not reached.
                out.write("\t\r\n\r\n");
                ^
===============================

I couldn't figure this out for a while until I understood out how to view
the java produced by the jsp code.  Because my case statement had
whitespaces between jsp tags the jasper engine decided to produce out.write
statements in the wrong place.

I modified my jsp to work but I wanted to ask if this was a bug.
I can just format my code differently, but it seems like a error other
newbies would make and I am sure it can get a bit nastier with more
complicated code. Is this behaviour part of the spec or can I expect
different implementations to behave differently.

Rodney

Here is a listing to reproduce the error.  I have fixed most of the
whitespace problem exept for the case statement just before monday.

==============================
<%!
java.util.Calendar todaysDate= java.util.Calendar.getInstance();
int myDay = todaysDate.get(todaysDate.DAY_OF_WEEK);
%>

<html>
<head>
<title>SWITCH</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<p><font size="-1" color="red">

<% switch (myDay) {
        case 1: %>
                Today is Sunday
<%              break; %>

<%      case 2: %>
                Today is Monday
<%              break;

        case 3: %>
                Today is Tuesday
<%              break;
        case 4: %>
                Today is Wednesday
<%              break;
        case 5:%>
                Today is Thursday
<%              break;
        case 6: %>
                Today is Friday
<%              break;
        case 7: %>
                Today is Saturday
<%              break;
        default: %>
                Invalid day of the week:
<%              break;
} %>

</font></p>
</body>
</html>

Reply via email to