Hi

Hey Jean only Sachin has given you the right solution. He is right that you will get a 
NullPointerException according to your sample of code. But I think probably you have 
missed one line which should be : ----

<%
  BufferedReader in = new BufferedReader(
                          new InputStreamReader(
                           yc.getInputStream()));

  String inputLine;

  try
  {
     inputLine = in.readLine(); //This is the missed line
  }
  catch(IOException exp)
  {
  }

  if ( inputLine.substring(0,1) == "1" ) {
    out.println("yes");
  }
  else {
     out.println("no");
  }
 %>

Now in the above code do apply the Sachin's suggestions.

P.S. - It is also right that it is not a JSP problem it is pure Java.

Thanks & Regards
Bhushan Bhangale
http://www.bbhangale.com

----- Original Message -----
Couple of things.
1) The code which you have sent us would throw a NullPointerException as the
string variable inputLine is null when you use it in the if statement.
2) Please do try to understand the difference between the == operator and
the equals(String s) method, it shall relieve you of a lot of problems later
on as well in your programming career :-).Just a friendly suggestion.
3) Another easier way could be to use the startsWith(String s) method of the
java.lang.String class.
Have a nice day.
With regards,
Sachin S. Khanna.
www.emailanorder.com

----- Original Message -----
From: Jean Chiang (]iN) <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, January 02, 2001 10:53 AM
Subject: The comparison between string and char.


> I am new to JSP. Who is going to help me? Thanks in advance.
> I read some input from a text file and the first parameter is an int and
> others are string. I have to do different action according to the first
> parameter.
> A part of my source code is listed as follows:
>
> In this case, when my first parameter is "1", it still shows "no". What's
> wrong? I suppose it cannot compare char and string. but how can I deal
with
> this stuff?
>
>
> <%   BufferedReader in = new BufferedReader(
>                          new InputStreamReader(
>                           yc.getInputStream()));
>
>  String inputLine;
>
> if ( inputLine.substring(0,1) == "1" ) {
>    out.println("yes");
>  }
> else {
>     out.println("no");
> }
> %>

Chequemail.com - a free web based e-mail service that also pays!!!
http://www.chequemail.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

Reply via email to