• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

returning else value

 
Megha Singhal
Ranch Hand
Posts: 225
IBM DB2 Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 225
IBM DB2 Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20170
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 225
IBM DB2 Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 411
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic