Hi Lance,

first, as already has been noted, Strings are checked for
equality by using equals(). Never saw something like
compareTo(); this performs a lexicographic comparison
and is to be considered bad style in this case.
Secondly, try adding a scriptlet end tag after the closing
brakes, like this: <% } <%>. You'll also have to add
another scriplet start tag before the 'else', of course.
May seem odd, but have a look at the final servlet
code. Note that this is dependant on the JSP engine
implementation; the only source of truth is the
servlet code that your specific implementation
finally produces.

HTH,

-- Chris (SCPJ2)

NB. Avoid naming something specific to your
application after something that has a fixed
meaning. Collection is an interface in java.util
with a fundamental role in the Collection
API (introduced in 1.2), and due to the Java
coding style guide, variables should always
start with a lowercase letter anyway :)

----- Original Message -----
From: "Lance Prais" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, June 22, 2002 5:16 AM
Subject: IF.. ELSE Problem


> I am through confused to as one the following if statement is not working:
> Could someone please look at it and let me know what I am doing wrong.  As
> you can see it is very simple.   You will se the output below the code
> <%@ page language="java" %>
> <%@ page import="java.util.*" %>
> <%@ page import="java.net.*" %>
>
> <%
>         String Collection="";
>         Collection = request.getParameter("collection");
> %>
> <%=Collection%>
>
>                 <%
> if (request.getParameter("collection")=="scopus")
>                 {%>
> You
>                 <%}
>                 else if (Collection=="securetrak")
>                 {%>
> me
>                 <%}
>                  else
>                 {%>
> they
>                 <%}%>
>
>
> OUTPUT:
> scopus they
>
> As you can see it is recognizing the "Collection "  but  ignoring the
> Statement.
>
> I am actually getting the following errors on Iplanet and do not
understand:
>
/usr/local/netscape/server4/https-kb-dev/config/../ClassCache/_jsps/_help_js
> p.java:89: 'try' without 'catch' or 'finally'.
>                 } else
>                   ^
>
/usr/local/netscape/server4/https-kb-dev/config/../ClassCache/_jsps/_help_js
> p.java:89: 'else' without 'if'.
>                 } else
>                   ^
>
/usr/local/netscape/server4/https-kb-dev/config/../ClassCache/_jsps/_help_js
> p.java:114: Type expected.
>         } catch (Exception ex) {
>           ^
> 5 errors
>
> Thank you in advance
>
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to