| Author |
returning else value
|
Megha Singhal
Ranch Hand
Joined: Feb 28, 2012
Posts: 133
|
|
in my following code i want to fetch the value of dropdown in the variable
following is my simple html code
<html>
<body>
<form name="my form" method="Post" action="Option">
State <select name="s2"><option>None</option>
<option value >UP</option>
<option value >Karnatka</option>
</select>
<input type="submit" value="submit">
</form>
</body>
</html>
and following is my servlet code
the above is returning only else value i.e. K in both the cases
i don't know why
|
 |
Megha Singhal
Ranch Hand
Joined: Feb 28, 2012
Posts: 133
|
|
Megha Singhal wrote:in my following code i want to fetch the value of dropdown in the variable
following is my simple html code
<html>
<body>
<form name="my form" method="Post" action="Option">
State<select name="s2"><option>None</option>
<option value >UP</option>
<option value >Karnatka</option>
</select>
<input type="submit" value="submit">
</form>
</body>
</html>
and following is my servlet code
the above is returning only else value i.e. K in both the cases
i don't know why
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
Don't use the == operator if you want to compare the contents of two String objects. That only tests whether the two references point to the same object, whereas two different String objects can contain the same sequence of characters. Use the equals() method instead:
|
 |
Megha Singhal
Ranch Hand
Joined: Feb 28, 2012
Posts: 133
|
|
Paul Clapham wrote:
Don't use the == operator if you want to compare the contents of two String objects. That only tests whether the two references point to the same object, whereas two different String objects can contain the same sequence of characters. Use the equals() method instead:
Thanks its working.
|
 |
sai rama krishna
Ranch Hand
Joined: May 29, 2009
Posts: 133
|
|
Here is interesting link, explanation
All objects have both identity (the object's location in memory) and state (the object's data). The == operator always compares identity. The default implementation of equals compares identity as well.
Sometimes the default implementation of equals has the desired behaviour (as in a type-safe enumeration, for example), but equals should usually compare state, not identity. This is particularly true for "data-centric" classes which map to database records.
http://www.javapractices.com/topic/TopicAction.do?Id=17
|
 |
 |
|
|
subject: returning else value
|
|
|