You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Massimiliano PASQUALONI <ma...@data-processing.it> on 2007/05/22 16:39:59 UTC

"if" don't work?!?!?

Hi guy!
 
Wat's happen??
 
If i read an checkrequest post

    String Pippo = request.getParameter("abilitato");

    out.print(Pippo);

return me= on

If I try to make a condition whit if:

 

   if (Pippo == "on") {

            ............    

        }

these don't work
 
And is'nt the first time, 
 
if I try
 
    Pippo =  request.getParameter("abilitato");
    Pluto =  request.getParameter("abilitato");
 
the if (Pippo == Pluto )  don't work!
 
 
 
:-(
 
please, help me!

Massimiliano PASQUALONI

Data Processing S.r.l.
Reparto EDP
S.S. 100 BA-TA Km 18
c/o "IL BARICENTRO" 
torre D
70010 CASAMASSIMA (BA)

Re: "if" don't work?!?!?

Posted by David Delbecq <de...@oma.be>.
Basics of java programming: == operator compare objet instances, not
their content.
To check if 2 differences instance are the same, use the equals() method.
Eg:

if (Pippo.equals("on")) {
...
}

You should probably start by learning java language (J2SE) before you
start learning java enterprise (J2EE).

En l'instant précis du 22/05/07 16:39, Massimiliano PASQUALONI
s'exprimait en ces termes:
> Hi guy!
>  
> Wat's happen??
>  
> If i read an checkrequest post
>
>     String Pippo = request.getParameter("abilitato");
>
>     out.print(Pippo);
>
> return me= on
>
> If I try to make a condition whit if:
>
>  
>
>    if (Pippo == "on") {
>
>             ............    
>
>         }
>
> these don't work
>  
> And is'nt the first time, 
>  
> if I try
>  
>     Pippo =  request.getParameter("abilitato");
>     Pluto =  request.getParameter("abilitato");
>  
> the if (Pippo == Pluto )  don't work!
>  
>  
>  
> :-(
>  
> please, help me!
>
> Massimiliano PASQUALONI
>
> Data Processing S.r.l.
> Reparto EDP
> S.S. 100 BA-TA Km 18
> c/o "IL BARICENTRO" 
> torre D
> 70010 CASAMASSIMA (BA)
>
>   


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT] "if" don't work?!?!?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jost Richstein [mailto:jrichstein@softdecc.com] 
> Subject: Re: [OT] "if" don't work?!?!?
> 
> No, that is not guaranteed to be false.
> For example
>    Pippo.intern() == Pluto.intern()
> should be true.

The above certainly is correct, but is not what the OP coded.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] "if" don't work?!?!?

Posted by Jost Richstein <jr...@softdecc.com>.
No, that is not guaranteed to be false.
For example

   Pippo.intern() == Pluto.intern()

should be true.

Caldarale, Charles R schrieb:
>> From: Massimiliano PASQUALONI 
>> [mailto:massimiliano.pasqualoni@data-processing.it] 
>> Subject: "if" don't work?!?!?
>>
>>    if (Pippo == "on") {
>>     
>
> Guaranteed to be false.
>
>   
>>     Pippo =  request.getParameter("abilitato");
>>     Pluto =  request.getParameter("abilitato");
>>  
>> the if (Pippo == Pluto )  don't work!
>>     
>
> Also guaranteed to be false.
>
> You need to learn Java before embarking on writing webapps for any
> container.  The test you're making is one for object equality, not
> content equality.  Your expression should be something like:
>
>     if (Pippo.equals("on"))
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
>
>   

-- 
Jost Richstein
SoftDeCC Software GmbH
Email: jrichstein@softdecc.com
Tel.: +49 89 89 06 78 47
Fax.: +49 89 89 06 78 33

SoftDeCC Software GmbH; Gesellschaft mit beschränkter Haftung; Sitz der Gesellschaft: München; Registergericht: München, HRB 123667; Geschäftsführer: Ralf Malis, Georg Nüssel, Jost Richstein, Gerd Wilts



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] "if" don't work?!?!?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
>> Subject: Re: [OT] "if" don't work?!?!?
>>
>> String Pippo = "on";
>>
>> if(Pippo == "on")
>>    System.err.println("Pippo is on, man!");
> 
> Again, that's not what the OP coded; Pippo was retrieved from the
> request, not set to a constant.  Changing the context of the if
> statement can certainly changes the result.

Agreed. Your quote, however, was out of context. You only showed the
comparison between a (most likely String) reference type and a literal
string and asserted that it was guaranteed not to work. In that context
(i.e. none), your statement was not true.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD4DBQFGU0vc9CaO5/Lv0PARAptfAJd/xAWaVEtfhSAnSYhGMvKGqpEVAJ9KE5hq
BvycOhmewUhMklkNDbeatg==
=wizm
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT] "if" don't work?!?!?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Christopher Schultz [mailto:chris@christopherschultz.net] 
> Subject: Re: [OT] "if" don't work?!?!?
> 
> String Pippo = "on";
> 
> if(Pippo == "on")
>    System.err.println("Pippo is on, man!");

Again, that's not what the OP coded; Pippo was retrieved from the
request, not set to a constant.  Changing the context of the if
statement can certainly changes the result.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: [OT] "if" don't work?!?!?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chuck,

Caldarale, Charles R wrote:
>> From: Massimiliano PASQUALONI 
>> [mailto:massimiliano.pasqualoni@data-processing.it] 
>> Subject: "if" don't work?!?!?
>>
>>    if (Pippo == "on") {
> 
> Guaranteed to be false.

Not always:

String Pippo = "on";

if(Pippo == "on")
   System.err.println("Pippo is on, man!");

...will print the string ;)

But, of course, this is a /super/ special case where Java's constant
pool is involved. Someone who doesn't understand why "Pippo == "on"
doesn't always work is going to have their mind blown by the constant pool.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGUzc99CaO5/Lv0PARAoktAJ0aTbR2XlrB3CD6PjMUlEsJMIO0pwCgn1zy
SwD0cbGDStbYkxoYtcummaI=
=J+fl
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: [OT] "if" don't work?!?!?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Massimiliano PASQUALONI 
> [mailto:massimiliano.pasqualoni@data-processing.it] 
> Subject: "if" don't work?!?!?
> 
>    if (Pippo == "on") {

Guaranteed to be false.

>     Pippo =  request.getParameter("abilitato");
>     Pluto =  request.getParameter("abilitato");
>  
> the if (Pippo == Pluto )  don't work!

Also guaranteed to be false.

You need to learn Java before embarking on writing webapps for any
container.  The test you're making is one for object equality, not
content equality.  Your expression should be something like:

    if (Pippo.equals("on"))

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: R: "if" don't work?!?!?

Posted by David Delbecq <de...@oma.be>.
Nope, this only works if the string is a variant of True, not on the 1,
yes, si cases :)
Also, only value supposed to be sent by browser is the value="...."
field of input checkbox. And html 4 specs states that for checkboxes and
radio boxes this value *must* be present in html :)


Yeah, i too thought to post this request on sidebar. Long time not seen
a Paula related stuff. Did you code a Calculator recently? :D

Christopher Schultz a écrit :
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Massimiliano,
>
> Massimiliano PASQUALONI wrote:
>
> String Paula = "Brilliant";
>
> You can replace all the code below with this gem:
>
> boolean myBoolean = Boolean.valueOf(yourString).booleanValue();
>
> Don't try to re-invent the wheel. Most of the things like this have
> already been done by someone else, and probably better. So, learn from
> and take advantage of the work others have done before you.
>
>   
>> public boolean StringToBoolean(String StrBool)
>> 	 {
>> 	 	boolean convertito=false;
>>
>> 		if ((StrBool ==	"1") || (StrBool == "On") || (StrBool ==
>> "on") || (StrBool == "Yes") || (StrBool == "yes") || (StrBool == "Si") ||
>> (StrBool == "si") || (StrBool == "True") || (StrBool == "true"))
>> 			{
>> 				convertito = true;
>> 			}
>>
>> 		if ((StrBool == "0") || (StrBool == "Off") || (StrBool ==
>> "off") || (StrBool ==	"No") || (StrBool == "no") || (StrBool == "False")
>> || (StrBool == "false"))
>> 			{
>> 				convertito = false;
>> 			}
>>
>> 	 	return convertito;
>> 	 }
>>     
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGUzgE9CaO5/Lv0PARAlJJAJ9XdavG7OXesi3bTaqMVdrJe3nUqwCgwuNU
> 2K2hHPrMKDH8NLAHvKcR8ek=
> =fK6t
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>   

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: R: "if" don't work?!?!?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Massimiliano,

Massimiliano PASQUALONI wrote:

String Paula = "Brilliant";

You can replace all the code below with this gem:

boolean myBoolean = Boolean.valueOf(yourString).booleanValue();

Don't try to re-invent the wheel. Most of the things like this have
already been done by someone else, and probably better. So, learn from
and take advantage of the work others have done before you.

> public boolean StringToBoolean(String StrBool)
> 	 {
> 	 	boolean convertito=false;
> 
> 		if ((StrBool ==	"1") || (StrBool == "On") || (StrBool ==
> "on") || (StrBool == "Yes") || (StrBool == "yes") || (StrBool == "Si") ||
> (StrBool == "si") || (StrBool == "True") || (StrBool == "true"))
> 			{
> 				convertito = true;
> 			}
> 
> 		if ((StrBool == "0") || (StrBool == "Off") || (StrBool ==
> "off") || (StrBool ==	"No") || (StrBool == "no") || (StrBool == "False")
> || (StrBool == "false"))
> 			{
> 				convertito = false;
> 			}
> 
> 	 	return convertito;
> 	 }

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGUzgE9CaO5/Lv0PARAlJJAJ9XdavG7OXesi3bTaqMVdrJe3nUqwCgwuNU
2K2hHPrMKDH8NLAHvKcR8ek=
=fK6t
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


R: R: "if" don't work?!?!?

Posted by Massimiliano PASQUALONI <ma...@data-processing.it>.
No, I don't have set any value ont the checkbox, is a boolean choise, I use
the default value.


I think i've fixed my page whit the equals method...


I'm sorry for the nuisance, heartfelt thanks to every Tomcat Users, bye!



Massimiliano


-----Messaggio originale-----
Da: Edoardo Panfili [mailto:edoardo@aspix.it] 
Inviato: martedì 22 maggio 2007 17.06
A: Tomcat Users List
Oggetto: Re: R: "if" don't work?!?!?

Massimiliano PASQUALONI ha scritto:
> No, don't work!
> 
> Im try a simple function in my javabean that "convert" from string to
> boolean:
> 
> JSP:
> String Prova = request.getParameter("abilitato");
>  // where abilitato is a checkbox in a form
can you post the HTML fragment of the form?
Do you have somethinkg like
<input name="abilitato" value="si" type="checkbox"> ?
check the value of "value" attribute of "input" element

Edoardo

> 
> 
> 
> 
> 
> Javabean:
> 
> public boolean StringToBoolean(String StrBool)
> 	 {
> 	 	boolean convertito=false;
> 
> 		if ((StrBool ==	"1") || (StrBool == "On") || (StrBool ==
> "on") || (StrBool == "Yes") || (StrBool == "yes") || (StrBool == "Si") 
> || (StrBool == "si") || (StrBool == "True") || (StrBool == "true"))
> 			{
> 				convertito = true;
> 			}
> 
> 		if ((StrBool == "0") || (StrBool == "Off") || (StrBool ==
> "off") || (StrBool ==	"No") || (StrBool == "no") || (StrBool == "False")
> || (StrBool == "false"))
> 			{
> 				convertito = false;
> 			}
> 
> 	 	return convertito;
> 	 }
>  
> 
> 
> 
> 
> 
> 
> 
> If I try
> 
>  	if ("on".equals(request.getParameter("abilitato"))){
> 				Abilitato = true;
> 			}
> 
> 
> 
> Or
> 
> 	 if (request.getParameter("abilitato").equals("on")){
> 				Abilitato = true;
> 			}
> 
> Or
> 
> 	if (request.getParameter("abilitato") == "on"){
> 				Abilitato = true;
> 			}
> 
> Or 
> 	Boolean Abilitato = bean.StringToBoolean(Prova);
> 
> 
> I have the same result: don't work..
> 
> 
> Yesterday I've try also
> 
> 	Referer = request.getHeader("Referer") 
> 	AltroReferer = request.getHeader("Referer")
> 
> 	if (Referer == AltroReferer ){...}
> 
> And don't work.....
> 
> 
> :-O
> 
> 
> 
> 
> -----Messaggio originale-----
> Da: Edoardo Panfili [mailto:edoardo@aspix.it]
> Inviato: martedì 22 maggio 2007 16.44
> A: Tomcat Users List
> Oggetto: Re: "if" don't work?!?!?
> 
> Massimiliano PASQUALONI ha scritto:
>> Hi guy!
>>  
>> Wat's happen??
>>  
>> If i read an checkrequest post
>>
>>     String Pippo = request.getParameter("abilitato");
>>
>>     out.print(Pippo);
>>
>> return me= on
>>
>> If I try to make a condition whit if:
>>
>>  
>>
>>    if (Pippo == "on") {
>>
>>             ............    
>>
>>         }
> 
> Maybe possible that I don't understand...
> 
> String pippo = request.getParameter("abilitato");
> if (pippo.equals("on")) {
> 	// ...
> }
> 
> 
> Edoardo
> 


--
edoardo@aspix.it
AIM: edoardopn
Jabber: edoardopa@talk.google.com
tel:075 9142766

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe,
e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Scanned with Copfilter Version 0.83beta3a (ProxSMTP 1.4)
AntiVirus: ClamAV 0.88.4/3281 - Tue May 22 10:50:43 2007
by Markus Madlener @ http://www.copfilter.org

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: R: "if" don't work?!?!?

Posted by Edoardo Panfili <ed...@aspix.it>.
Massimiliano PASQUALONI ha scritto:
> No, don't work!
> 
> Im try a simple function in my javabean that "convert" from string to
> boolean:
> 
> JSP:
> String Prova = request.getParameter("abilitato");
>  // where abilitato is a checkbox in a form
can you post the HTML fragment of the form?
Do you have somethinkg like
<input name="abilitato" value="si" type="checkbox">
?
check the value of "value" attribute of "input" element

Edoardo

> 
> 
> 
> 
> 
> Javabean:
> 
> public boolean StringToBoolean(String StrBool)
> 	 {
> 	 	boolean convertito=false;
> 
> 		if ((StrBool ==	"1") || (StrBool == "On") || (StrBool ==
> "on") || (StrBool == "Yes") || (StrBool == "yes") || (StrBool == "Si") ||
> (StrBool == "si") || (StrBool == "True") || (StrBool == "true"))
> 			{
> 				convertito = true;
> 			}
> 
> 		if ((StrBool == "0") || (StrBool == "Off") || (StrBool ==
> "off") || (StrBool ==	"No") || (StrBool == "no") || (StrBool == "False")
> || (StrBool == "false"))
> 			{
> 				convertito = false;
> 			}
> 
> 	 	return convertito;
> 	 }
>  
> 
> 
> 
> 
> 
> 
> 
> If I try 
> 
>  	if ("on".equals(request.getParameter("abilitato"))){
> 				Abilitato = true;
> 			}
> 
> 
> 
> Or 
> 
> 	 if (request.getParameter("abilitato").equals("on")){
> 				Abilitato = true;
> 			}
> 
> Or
> 
> 	if (request.getParameter("abilitato") == "on"){
> 				Abilitato = true;
> 			}
> 
> Or 
> 	Boolean Abilitato = bean.StringToBoolean(Prova);
> 
> 
> I have the same result: don't work..
> 
> 
> Yesterday I've try also
> 
> 	Referer = request.getHeader("Referer") 
> 	AltroReferer = request.getHeader("Referer") 
> 
> 	if (Referer == AltroReferer ){...}
> 
> And don't work.....
> 
> 
> :-O
> 
> 
> 
> 
> -----Messaggio originale-----
> Da: Edoardo Panfili [mailto:edoardo@aspix.it] 
> Inviato: martedì 22 maggio 2007 16.44
> A: Tomcat Users List
> Oggetto: Re: "if" don't work?!?!?
> 
> Massimiliano PASQUALONI ha scritto:
>> Hi guy!
>>  
>> Wat's happen??
>>  
>> If i read an checkrequest post
>>
>>     String Pippo = request.getParameter("abilitato");
>>
>>     out.print(Pippo);
>>
>> return me= on
>>
>> If I try to make a condition whit if:
>>
>>  
>>
>>    if (Pippo == "on") {
>>
>>             ............    
>>
>>         }
> 
> Maybe possible that I don't understand...
> 
> String pippo = request.getParameter("abilitato");
> if (pippo.equals("on")) {
> 	// ...
> }
> 
> 
> Edoardo
> 


-- 
edoardo@aspix.it
AIM: edoardopn
Jabber: edoardopa@talk.google.com
tel:075 9142766

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: "if" don't work?!?!?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bryce,

Bryce Burgess (bburgess) wrote:
> Would this work for you?
> ( http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#toLowerCase() )

String.equalsIgnoreCase is much better.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGUzhA9CaO5/Lv0PARAov3AJwJ1Pb0vyNKuBhdcKiobNLWfTntZwCgumW8
7HZczna2SiSQ1sGZ3d2ZtRs=
=08+U
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: "if" don't work?!?!?

Posted by "Bryce Burgess (bburgess)" <bb...@cisco.com>.
Would this work for you?
( http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#toLowerCase() )

Javabean:

public boolean StringToBoolean(String StrBool)
	 {
	 boolean convertito=false;
       // since the default is false, only need to check the true... 
       // If any of these are true, return true, else return false (on any string of characters...)

if ((contentEquals(toLowerCase(StrBool) "1"))    || 
    (contentEquals(toLowerCase(StrBool) "on"))   || 
    (contentEquals(toLowerCase(StrBool) "yes"))  || 
    (contentEquals(toLowerCase(StrBool) "si"))   || 
    (contentEquals(toLowerCase(StrBool) "true")) )
		{
		convertito = true;
		}

	 return convertito;
	 }



-----Original Message-----
From: Massimiliano PASQUALONI [mailto:massimiliano.pasqualoni@data-processing.it] 
Sent: Tuesday, May 22, 2007 9:58 AM
To: 'Tomcat Users List'
Subject: R: "if" don't work?!?!?

No, don't work!

Im try a simple function in my javabean that "convert" from string to
boolean:

JSP:
String Prova = request.getParameter("abilitato");
 // where abilitato is a checkbox in a form





Javabean:

public boolean StringToBoolean(String StrBool)
	 {
	 	boolean convertito=false;



		if ((StrBool == "0") || (StrBool == "Off") || (StrBool ==
"off") || (StrBool ==	"No") || (StrBool == "no") || (StrBool == "False")
|| (StrBool == "false"))
			{
				convertito = false;
			}

	 	return convertito;
	 }
 







If I try 

 	if ("on".equals(request.getParameter("abilitato"))){
				Abilitato = true;
			}



Or 

	 if (request.getParameter("abilitato").equals("on")){
				Abilitato = true;
			}

Or

	if (request.getParameter("abilitato") == "on"){
				Abilitato = true;
			}

Or 
	Boolean Abilitato = bean.StringToBoolean(Prova);


I have the same result: don't work..


Yesterday I've try also

	Referer = request.getHeader("Referer") 
	AltroReferer = request.getHeader("Referer") 

	if (Referer == AltroReferer ){...}

And don't work.....


:-O




-----Messaggio originale-----
Da: Edoardo Panfili [mailto:edoardo@aspix.it]
Inviato: martedì 22 maggio 2007 16.44
A: Tomcat Users List
Oggetto: Re: "if" don't work?!?!?

Massimiliano PASQUALONI ha scritto:
> Hi guy!
>  
> Wat's happen??
>  
> If i read an checkrequest post
> 
>     String Pippo = request.getParameter("abilitato");
> 
>     out.print(Pippo);
> 
> return me= on
> 
> If I try to make a condition whit if:
> 
>  
> 
>    if (Pippo == "on") {
> 
>             ............    
> 
>         }

Maybe possible that I don't understand...

String pippo = request.getParameter("abilitato");
if (pippo.equals("on")) {
	// ...
}


Edoardo

--
edoardo@aspix.it
AIM: edoardopn
Jabber: edoardopa@talk.google.com
tel:075 9142766

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe,
e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Scanned with Copfilter Version 0.83beta3a (ProxSMTP 1.4)
AntiVirus: ClamAV 0.88.4/3281 - Tue May 22 10:50:43 2007 by Markus Madlener @ http://www.copfilter.org

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: R: "if" don't work?!?!?

Posted by David Delbecq <de...@oma.be>.
Massimiliano PASQUALONI a écrit :
> public boolean StringToBoolean(String StrBool)
> 	 {
> 	 	boolean convertito=false;
>
> 		if ((StrBool ==	"1") || (StrBool == "On") || (StrBool ==
> "on") || (StrBool == "Yes") || (StrBool == "yes") || (StrBool == "Si") ||
> (StrBool == "si") || (StrBool == "True") || (StrBool == "true"))
> 			{
> 				convertito = true;
> 			}
>
> 		if ((StrBool == "0") || (StrBool == "Off") || (StrBool ==
> "off") || (StrBool ==	"No") || (StrBool == "no") || (StrBool == "False")
> || (StrBool == "false"))
> 			{
> 				convertito = false;
> 			}
>
> 	 	return convertito;
> 	 }
>   
OMG :)
> If I try 
>
>  	if ("on".equals(request.getParameter("abilitato"))){
> 				Abilitato = true;
> 			}
>
>
>   
Works if parameter abilitato is 'on' (not 'On' or 'checked' or whatever
other browser is using)
> Or 
>
> 	 if (request.getParameter("abilitato").equals("on")){
> 				Abilitato = true;
> 			}
>   
same as above. Also if checkbox is not checked, most browser don't send
parameter an you will end up with a NullPointerException. Check
parameter is not null before calling equals()
> Or
>
> 	if (request.getParameter("abilitato") == "on"){
> 				Abilitato = true;
> 			}
>   
Omg² :)
> 	Referer = request.getHeader("Referer") 
> 	AltroReferer = request.getHeader("Referer") 
>
> 	if (Referer == AltroReferer ){...}
>
>   
As already said, not garanteed to work


I recommend you read this:
http://jamesthornton.com/eckel/TIJ-3rd-edition4.0/TIJ303.htm

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


R: "if" don't work?!?!?

Posted by Massimiliano PASQUALONI <ma...@data-processing.it>.
No, don't work!

Im try a simple function in my javabean that "convert" from string to
boolean:

JSP:
String Prova = request.getParameter("abilitato");
 // where abilitato is a checkbox in a form





Javabean:

public boolean StringToBoolean(String StrBool)
	 {
	 	boolean convertito=false;

		if ((StrBool ==	"1") || (StrBool == "On") || (StrBool ==
"on") || (StrBool == "Yes") || (StrBool == "yes") || (StrBool == "Si") ||
(StrBool == "si") || (StrBool == "True") || (StrBool == "true"))
			{
				convertito = true;
			}

		if ((StrBool == "0") || (StrBool == "Off") || (StrBool ==
"off") || (StrBool ==	"No") || (StrBool == "no") || (StrBool == "False")
|| (StrBool == "false"))
			{
				convertito = false;
			}

	 	return convertito;
	 }
 







If I try 

 	if ("on".equals(request.getParameter("abilitato"))){
				Abilitato = true;
			}



Or 

	 if (request.getParameter("abilitato").equals("on")){
				Abilitato = true;
			}

Or

	if (request.getParameter("abilitato") == "on"){
				Abilitato = true;
			}

Or 
	Boolean Abilitato = bean.StringToBoolean(Prova);


I have the same result: don't work..


Yesterday I've try also

	Referer = request.getHeader("Referer") 
	AltroReferer = request.getHeader("Referer") 

	if (Referer == AltroReferer ){...}

And don't work.....


:-O




-----Messaggio originale-----
Da: Edoardo Panfili [mailto:edoardo@aspix.it] 
Inviato: martedì 22 maggio 2007 16.44
A: Tomcat Users List
Oggetto: Re: "if" don't work?!?!?

Massimiliano PASQUALONI ha scritto:
> Hi guy!
>  
> Wat's happen??
>  
> If i read an checkrequest post
> 
>     String Pippo = request.getParameter("abilitato");
> 
>     out.print(Pippo);
> 
> return me= on
> 
> If I try to make a condition whit if:
> 
>  
> 
>    if (Pippo == "on") {
> 
>             ............    
> 
>         }

Maybe possible that I don't understand...

String pippo = request.getParameter("abilitato");
if (pippo.equals("on")) {
	// ...
}


Edoardo

--
edoardo@aspix.it
AIM: edoardopn
Jabber: edoardopa@talk.google.com
tel:075 9142766

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe,
e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Scanned with Copfilter Version 0.83beta3a (ProxSMTP 1.4)
AntiVirus: ClamAV 0.88.4/3281 - Tue May 22 10:50:43 2007
by Markus Madlener @ http://www.copfilter.org

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: "if" don't work?!?!?

Posted by Edoardo Panfili <ed...@aspix.it>.
Massimiliano PASQUALONI ha scritto:
> Hi guy!
>  
> Wat's happen??
>  
> If i read an checkrequest post
> 
>     String Pippo = request.getParameter("abilitato");
> 
>     out.print(Pippo);
> 
> return me= on
> 
> If I try to make a condition whit if:
> 
>  
> 
>    if (Pippo == "on") {
> 
>             ............    
> 
>         }

Maybe possible that I don't understand...

String pippo = request.getParameter("abilitato");
if (pippo.equals("on")) {
	// ...
}


Edoardo

-- 
edoardo@aspix.it
AIM: edoardopn
Jabber: edoardopa@talk.google.com
tel:075 9142766

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: "if" don't work?!?!?

Posted by Jost Richstein <jr...@softdecc.com>.
Have you tried

   if("on".equals(Pippo)) {
       ....
   }

Massimiliano PASQUALONI schrieb:
> Hi guy!
>  
> Wat's happen??
>  
> If i read an checkrequest post
>
>     String Pippo = request.getParameter("abilitato");
>
>     out.print(Pippo);
>
> return me= on
>
> If I try to make a condition whit if:
>
>  
>
>    if (Pippo == "on") {
>
>             ............    
>
>         }
>
> these don't work
>  
> And is'nt the first time, 
>  
> if I try
>  
>     Pippo =  request.getParameter("abilitato");
>     Pluto =  request.getParameter("abilitato");
>  
> the if (Pippo == Pluto )  don't work!
>  
>  
>  
> :-(
>  
> please, help me!
>
> Massimiliano PASQUALONI
>
> Data Processing S.r.l.
> Reparto EDP
> S.S. 100 BA-TA Km 18
> c/o "IL BARICENTRO" 
> torre D
> 70010 CASAMASSIMA (BA)
>
>   

-- 
Jost Richstein
SoftDeCC Software GmbH
Email: jrichstein@softdecc.com
Tel.: +49 89 89 06 78 47
Fax.: +49 89 89 06 78 33

SoftDeCC Software GmbH; Gesellschaft mit beschränkter Haftung; Sitz der Gesellschaft: München; Registergericht: München, HRB 123667; Geschäftsführer: Ralf Malis, Georg Nüssel, Jost Richstein, Gerd Wilts



---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: OT: "if" don't work?!?!?

Posted by DJ...@desknetinc.com.
This is not really a Tomcat question, but a matter of Java language 
understanding.
Comparators like ==, >, <=, etc. should only be used with java language 
primitive types, such as int, byte, boolean, and NOT with Objects, like 
String, as you are, UNLESS you actually wish to test whether the two 
things you are comparing are the same object instance.  To test whether 
two distinct objects represent the same value or entity, use the equals 
method.  So in your case, you should use:

if (Pippo.equals("on")) { ... }

or 

if (Pippo.equals(Pluto)) { ... }



Please respond to "Tomcat Users List" <us...@tomcat.apache.org>

To:     "'Tomcat Users List'" <us...@tomcat.apache.org>
cc:      
Subject:        "if" don't work?!?!?


Hi guy!

Wat's happen??

If i read an checkrequest post

String Pippo = request.getParameter("abilitato");

out.print(Pippo);

return me= on

If I try to make a condition whit if:



if (Pippo == "on") {

............

}

these don't work

And is'nt the first time,

if I try

Pippo =  request.getParameter("abilitato");
Pluto =  request.getParameter("abilitato");

the if (Pippo == Pluto )  don't work!



:-(

please, help me!

Massimiliano PASQUALONI

Data Processing S.r.l.
Reparto EDP
S.S. 100 BA-TA Km 18
c/o "IL BARICENTRO"
torre D
70010 CASAMASSIMA (BA)