You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by George Hester <he...@hotmail.com> on 2004/02/24 03:03:32 UTC

What's the problem with Tomcat 4.1.29 and Switch?

In Tomacat this works fine:

<-- switch.jsp -->
<!-- BEGIN -->
<!doctype html public "-//W3C//DTD HTML 4.0 Final//EN">
<%
int day = 3;
%>
<html>
<head>
<title>Test Switch</title>
</head>
<body>
<% switch (day) {
 case 1:
  out.println("Sunday");
  break;
 case 2:
  out.println("Monday");
  break;
 default:
  out.println("No day");
  break;
   } %>
</body>
</html>
<!-- END -->

but this does NOT

<-- switch.jsp -->
<!-- BEGIN -->
<!doctype html public "-//W3C//DTD HTML 4.0 Final//EN">
<%
int day = 3;
%>
<html>
<head>
<title>Test Switch</title>
</head>
<body>
<% switch (day) { %>
 <% case 1:
  out.println("Sunday");
  break;
 case 2:
  out.println("Monday");
  break;
 default:
  out.println("No day");
  break;
   } %>
</body>
</html>
<!-- END -->

-- 
George Hester
__________________________________


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


Re: What's the problem with Tomcat 4.1.29 and Switch?

Posted by David Rees <dr...@greenhydrant.com>.
> Thanks.  I wish Damon Hougland and Aaron Tavistock knew that before they
> published their Sun sanctioned book.  It would have saved me a lot of
> frustration.  I really expected Sun's CORE books to be better then Wrox.
> 
> Their example was this which failed:
> 
> <% switch (day) { %>
> <% case 1: %>
>    <font color="blue" size="+1">Sunday</font>
>    <% break; %>
> <% case 2: %>
>    <font color="blue" size="+1">Monday</font>
>    <% break; %>
> <% default: %>
>    <font color="blue" size="+1">No day</font>
>    <% break; %>
> <% } %>

If you want to use a switch, this should work:

<% switch (day) {
    case 1: %>
    <font color="blue" size="+1">Sunday</font>
    <% break; %>
<% case 2: %>
    <font color="blue" size="+1">Monday</font>
    <% break; %>
<% default: %>
    <font color="blue" size="+1">No day</font>
    <% break; } %>

But really, the best way to do it is to use JSTL instead of scriptlets 
like this:

<c:choose>
   <c:when test="${day == 1}">
     <font color="blue" size="+1">Sunday</font>
   </c:when>
   <c:when test="${day == 2}">
     <font color="blue" size="+1">Monday</font>
   </c:when>
   <c:otherwise>
     <font color="blue" size="+1">No day</font>
   </c:otherwise>
</c:choose>

Much more readable, too.

-Dave

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


Re: What's the problem with Tomcat 4.1.29 and Switch?

Posted by Parsons Technical Services <pa...@earthlink.net>.
Okay, so I learned something. I was right but also wrong. As I said "my"
understanding which now is New and Improved. Use ifs not switches on jsp.
Got to write that down somewhere .....

Sorry George.

Doug

----- Original Message ----- 
From: "George Hester" <he...@hotmail.com>
To: <to...@jakarta.apache.org>
Sent: Monday, February 23, 2004 10:22 PM
Subject: Re: What's the problem with Tomcat 4.1.29 and Switch?


Thanks.  I wish Damon Hougland and Aaron Tavistock knew that before they
published their Sun sanctioned book.  It would have saved me a lot of
frustration.  I really expected Sun's CORE books to be better then Wrox.

Their example was this which failed:

<% switch (day) { %>
<% case 1: %>
   <font color="blue" size="+1">Sunday</font>
   <% break; %>
<% case 2: %>
   <font color="blue" size="+1">Monday</font>
   <% break; %>
<% default: %>
   <font color="blue" size="+1">No day</font>
   <% break; %>
<% } %>

-- 
George Hester
__________________________________
"Carl Howells" <ch...@janrain.com> wrote in message
news:403ABEAA.7020007@janrain.com...
> Because the switch statement has different syntax.
>
>    <% switch (day) { %>
>     <% case 1: // and so on...
>    %>
>
> Could be translated to:
>    switch (day) {
>    out.print("\n ");
>    case 1: // and so on...
>
> Which is clearly illegal syntax.  There is no equivalent illegal form of
> any other block construct, which is why this only shows up with switch
> statements.
>
> George Hester wrote:
> > Well according to Core JSP by Damon Hougland and Aaron Tavistock © 2001
Prentice Hall (pgs 26-28) it should work.
> >
> > For example this works:
> >
> >   <% if (day == 1 | day == 7){ %>
> >    <font color="red" size="+1">
> >    It's the weekend!</font>
> >   <% } else { %>
> >    <font color="red" size="+1">
> >    Still in the work week.</font>
> >   <% } %>
> >
> > then why not the same for the switch?  Note if breaking these tags up
for the if - then - else (as shown above) like in the switch I showed you
then by transference we'd have to conclude that the above if - then - else
wouldn't work either.  But it does.
> >
> > So I'm confused.  Why can we break the tags up in if - then - else but
not in switch?
> >
> > hmmm...
> >


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




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


Re: What's the problem with Tomcat 4.1.29 and Switch?

Posted by George Hester <he...@hotmail.com>.
Ah neat.  I was wondering how to use the basic idea.  I showed it as out.println but I knew there had to be a better way.  Thanks much Antonio.

-- 
George Hester
__________________________________
"Antonio Fiol Bonnín" <fi...@terra.es> wrote in message news:403AFB68.2000903@terra.es...
> George Hester wrote:
> 
> >Thanks.  I wish Damon Hougland and Aaron Tavistock knew that before they published their Sun sanctioned book.  It would have saved me a lot of frustration.  I really expected Sun's CORE books to be better then Wrox.
> >
> >Their example was this which failed:
> >
> ><% switch (day) { %>
> ><% case 1: %>
> >   <font color="blue" size="+1">Sunday</font>
> >   <% break; %>
> ><% case 2: %>
> >   <font color="blue" size="+1">Monday</font>
> >   <% break; %>
> ><% default: %>
> >   <font color="blue" size="+1">No day</font>
> >   <% break; %>
> ><% } %>
> >
> >  
> >
> 
> I believe the following would work like a charm:
> 
> <% switch (day) { 
>    case 1: %>
>    <font color="blue" size="+1">Sunday</font>
> <% break; 
>    case 2: %>
>    <font color="blue" size="+1">Monday</font>
> <% break; 
>    default: %>
>    <font color="blue" size="+1">No day</font>
> <% break; 
>    } %>
> 
> 
> Keep the elements that need to be together really together.
> 
> 
> Antonio Fiol
> 


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


Re: What's the problem with Tomcat 4.1.29 and Switch?

Posted by Antonio Fiol Bonnín <fi...@terra.es>.
George Hester wrote:

>Thanks.  I wish Damon Hougland and Aaron Tavistock knew that before they published their Sun sanctioned book.  It would have saved me a lot of frustration.  I really expected Sun's CORE books to be better then Wrox.
>
>Their example was this which failed:
>
><% switch (day) { %>
><% case 1: %>
>   <font color="blue" size="+1">Sunday</font>
>   <% break; %>
><% case 2: %>
>   <font color="blue" size="+1">Monday</font>
>   <% break; %>
><% default: %>
>   <font color="blue" size="+1">No day</font>
>   <% break; %>
><% } %>
>
>  
>

I believe the following would work like a charm:

<% switch (day) { 
   case 1: %>
   <font color="blue" size="+1">Sunday</font>
<% break; 
   case 2: %>
   <font color="blue" size="+1">Monday</font>
<% break; 
   default: %>
   <font color="blue" size="+1">No day</font>
<% break; 
   } %>


Keep the elements that need to be together really together.


Antonio Fiol

Re: What's the problem with Tomcat 4.1.29 and Switch?

Posted by George Hester <he...@hotmail.com>.
Thanks.  I wish Damon Hougland and Aaron Tavistock knew that before they published their Sun sanctioned book.  It would have saved me a lot of frustration.  I really expected Sun's CORE books to be better then Wrox.

Their example was this which failed:

<% switch (day) { %>
<% case 1: %>
   <font color="blue" size="+1">Sunday</font>
   <% break; %>
<% case 2: %>
   <font color="blue" size="+1">Monday</font>
   <% break; %>
<% default: %>
   <font color="blue" size="+1">No day</font>
   <% break; %>
<% } %>

-- 
George Hester
__________________________________
"Carl Howells" <ch...@janrain.com> wrote in message news:403ABEAA.7020007@janrain.com...
> Because the switch statement has different syntax.
> 
>    <% switch (day) { %>
>     <% case 1: // and so on...
>    %>
> 
> Could be translated to:
>    switch (day) {
>    out.print("\n ");
>    case 1: // and so on...
> 
> Which is clearly illegal syntax.  There is no equivalent illegal form of 
> any other block construct, which is why this only shows up with switch 
> statements.
> 
> George Hester wrote:
> > Well according to Core JSP by Damon Hougland and Aaron Tavistock © 2001 Prentice Hall (pgs 26-28) it should work.
> > 
> > For example this works:
> > 
> >   <% if (day == 1 | day == 7){ %>
> >    <font color="red" size="+1">
> >    It's the weekend!</font>
> >   <% } else { %>
> >    <font color="red" size="+1">
> >    Still in the work week.</font>
> >   <% } %>
> > 
> > then why not the same for the switch?  Note if breaking these tags up for the if - then - else (as shown above) like in the switch I showed you then by transference we'd have to conclude that the above if - then - else wouldn't work either.  But it does.
> > 
> > So I'm confused.  Why can we break the tags up in if - then - else but not in switch?
> > 
> > hmmm...
> >


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


Re: What's the problem with Tomcat 4.1.29 and Switch?

Posted by Carl Howells <ch...@janrain.com>.
Because the switch statement has different syntax.

   <% switch (day) { %>
    <% case 1: // and so on...
   %>

Could be translated to:
   switch (day) {
   out.print("\n ");
   case 1: // and so on...

Which is clearly illegal syntax.  There is no equivalent illegal form of 
any other block construct, which is why this only shows up with switch 
statements.

George Hester wrote:
> Well according to Core JSP by Damon Hougland and Aaron Tavistock © 2001 Prentice Hall (pgs 26-28) it should work.
> 
> For example this works:
> 
>   <% if (day == 1 | day == 7){ %>
>    <font color="red" size="+1">
>    It's the weekend!</font>
>   <% } else { %>
>    <font color="red" size="+1">
>    Still in the work week.</font>
>   <% } %>
> 
> then why not the same for the switch?  Note if breaking these tags up for the if - then - else (as shown above) like in the switch I showed you then by transference we'd have to conclude that the above if - then - else wouldn't work either.  But it does.
> 
> So I'm confused.  Why can we break the tags up in if - then - else but not in switch?
> 
> hmmm...
> 

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


Re: What's the problem with Tomcat 4.1.29 and Switch?

Posted by George Hester <he...@hotmail.com>.
Well according to Core JSP by Damon Hougland and Aaron Tavistock © 2001 Prentice Hall (pgs 26-28) it should work.

For example this works:

  <% if (day == 1 | day == 7){ %>
   <font color="red" size="+1">
   It's the weekend!</font>
  <% } else { %>
   <font color="red" size="+1">
   Still in the work week.</font>
  <% } %>

then why not the same for the switch?  Note if breaking these tags up for the if - then - else (as shown above) like in the switch I showed you then by transference we'd have to conclude that the above if - then - else wouldn't work either.  But it does.

So I'm confused.  Why can we break the tags up in if - then - else but not in switch?

hmmm...

-- 
George Hester
__________________________________
"Parsons Technical Services" <pa...@earthlink.net> wrote in message news:02c601c3fa7e$8eba6770$7a01a8c0@ptslaptop...
> George,
> 
> OK, I'll bite. Why?
> 
> Not sure why you want to try this but from what I understand, no it won't
> work. The clue is that the jsp page is converted to a servlet and any code
> between the <% %> must stand on it own as valid code. When you split the
> code you have created two segments that if entered in a standard servlet
> could not stand on their own IF separated at ALL. Thus if the segregation
> was allowed then what would prevent you from inserting code between them?
> Thus when the servlet is created you then have two fragments of invalid code
> separated by other code. With that in mind, a simple test to determine if
> what you want is valid is to enter whatever you want between the  <% %> in a
> standard class and see if it complains.
> 
> Again this is from my understanding.
> 
> Doug Parsons
> www.parsonstechnical.com
> 
> 
> ----- Original Message ----- 
> From: "George Hester" <he...@hotmail.com>
> To: <to...@jakarta.apache.org>
> Sent: Monday, February 23, 2004 9:03 PM
> Subject: What's the problem with Tomcat 4.1.29 and Switch?
> 
> 
> In Tomacat this works fine:
> 
> <-- switch.jsp -->
> <!-- BEGIN -->
> <!doctype html public "-//W3C//DTD HTML 4.0 Final//EN">
> <%
> int day = 3;
> %>
> <html>
> <head>
> <title>Test Switch</title>
> </head>
> <body>
> <% switch (day) {
>  case 1:
>   out.println("Sunday");
>   break;
>  case 2:
>   out.println("Monday");
>   break;
>  default:
>   out.println("No day");
>   break;
>    } %>
> </body>
> </html>
> <!-- END -->
> 
> but this does NOT
> 
> <-- switch.jsp -->
> <!-- BEGIN -->
> <!doctype html public "-//W3C//DTD HTML 4.0 Final//EN">
> <%
> int day = 3;
> %>
> <html>
> <head>
> <title>Test Switch</title>
> </head>
> <body>
> <% switch (day) { %>
>  <% case 1:
>   out.println("Sunday");
>   break;
>  case 2:
>   out.println("Monday");
>   break;
>  default:
>   out.println("No day");
>   break;
>    } %>
> </body>
> </html>
> <!-- END -->
> 
> -- 
> George Hester
> __________________________________
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


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


Re: What's the problem with Tomcat 4.1.29 and Switch?

Posted by Parsons Technical Services <pa...@earthlink.net>.
George,

OK, I'll bite. Why?

Not sure why you want to try this but from what I understand, no it won't
work. The clue is that the jsp page is converted to a servlet and any code
between the <% %> must stand on it own as valid code. When you split the
code you have created two segments that if entered in a standard servlet
could not stand on their own IF separated at ALL. Thus if the segregation
was allowed then what would prevent you from inserting code between them?
Thus when the servlet is created you then have two fragments of invalid code
separated by other code. With that in mind, a simple test to determine if
what you want is valid is to enter whatever you want between the  <% %> in a
standard class and see if it complains.

Again this is from my understanding.

Doug Parsons
www.parsonstechnical.com


----- Original Message ----- 
From: "George Hester" <he...@hotmail.com>
To: <to...@jakarta.apache.org>
Sent: Monday, February 23, 2004 9:03 PM
Subject: What's the problem with Tomcat 4.1.29 and Switch?


In Tomacat this works fine:

<-- switch.jsp -->
<!-- BEGIN -->
<!doctype html public "-//W3C//DTD HTML 4.0 Final//EN">
<%
int day = 3;
%>
<html>
<head>
<title>Test Switch</title>
</head>
<body>
<% switch (day) {
 case 1:
  out.println("Sunday");
  break;
 case 2:
  out.println("Monday");
  break;
 default:
  out.println("No day");
  break;
   } %>
</body>
</html>
<!-- END -->

but this does NOT

<-- switch.jsp -->
<!-- BEGIN -->
<!doctype html public "-//W3C//DTD HTML 4.0 Final//EN">
<%
int day = 3;
%>
<html>
<head>
<title>Test Switch</title>
</head>
<body>
<% switch (day) { %>
 <% case 1:
  out.println("Sunday");
  break;
 case 2:
  out.println("Monday");
  break;
 default:
  out.println("No day");
  break;
   } %>
</body>
</html>
<!-- END -->

-- 
George Hester
__________________________________


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




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