*
The moose likes Servlets and the fly likes returning else value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "returning else value" Watch "returning else value" New topic
Author

returning else value

Megha Singhal
Ranch Hand

Joined: Feb 28, 2012
Posts: 182

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: 182

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: 18541
    
    8



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: 182

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: 229
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: returning else value
 
Similar Threads
Newbie: Need help with checkbox post parameters
HTTP method POST is not supported by this url
Wierd problem
SimpleServlet.java:2: package javax.servlet does not exist
Wierd problem