So far, everyone who's given you an answer has given you the same incorrect
answer. Your code, modified to include the wrong answer, does this:
if (flag == null) {
// do something
}
if (flag.equals("download")) {
// do something else
}
Now, what do you think will happen when flag is null? Yep, that second test
will throw a NullPointerException.
You have two choices:
1) Change your second condition to 'else if' instead of just 'if'.
2) Use 'if ("download".equals(flag))' instead of 'if
(flag.equals("download"))'.
I would recommend that you *always* use (2) when you're comparing strings,
because it will never cause a NullPointerException.
--
Martin Cooper
----- Original Message -----
From: "sufi malak" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, March 12, 2001 10:42 AM
Subject: Re: simple jsp question ? thanks
> Now, I can not display the page when I changed flag == "download" to
> flag.equals("download") ???
> Here is the file services.jsp :
> <HTML>
> <BODY bgcolor="#ffffff">
> <%@ include file="Ttest3.html"%>
> <jsp:include page="Menu.jsp" flush="true">
> <jsp:param name="highlighted" value="services"/>
> </jsp:include>
> <% String flag = request.getParameter("flag"); %>
> <% System.out.println("flag = " + flag); %>
> <table bgcolor="effff">
> <tr>
> <td><a href="services.jsp?flag= <%= "download"
%>">Downloading</a></td>
> <td><a href="services.jsp?flag=upload">Uploading</a></td>
> </tr>
> </table>
> <%
> if (flag ==null)
> { %>
> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
>
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.ca
b#version=4,0,2,0"
> width="580" height="420">
> <param name=movie value="studentmain.swf">
> <param name=quality value=high>
> <embed src="../images/flash/studentmain.swf" quality=high
>
pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_
Version=ShockwaveFlash"
> type="application/x-shockwave-flash" width="580" height="420">
> </embed>
> </object>
> <% } %>
>
> <%
> System.out.println("Before if ..");
> System.out.println(flag);
> if (flag.equals("download"))
> { %>
> <%
> System.out.println("After if ..");
> System.out.println("downloading ..."); %>
> <%@ include file="download.html"%>
> <% } %>
> </BODY>
> </HTML>
>
>
>
> >From: "A.C." <[EMAIL PROTECTED]>
> >Reply-To: A mailing list about Java Server Pages specification and
> > reference <[EMAIL PROTECTED]>
> >To: [EMAIL PROTECTED]
> >Subject: Re: simple jsp question ? thanks
> >Date: Mon, 12 Mar 2001 20:27:17 +0200
> >
> > > Could you please just tell me, why when I click in the link
> >"Downloading" ,
> > > the if (flag == "download") is not working :
> >
> >two compare two strings:
> >if (string1.equals(string2))
> >...
> >
>
>===========================================================================
> >To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> >JSP-INTEREST".
> >For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> >DIGEST".
> >Some relevant FAQs on JSP/Servlets can be found at:
> >
> > http://java.sun.com/products/jsp/faq.html
> > http://www.esperanto.org.nz/jsp/jspfaq.html
> > http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> > http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets