This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes returning else value Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "returning else value" Watch "returning else value" New topic
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
    
    2



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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: returning else value
 
Similar Threads
Newbie: Need help with checkbox post parameters
Wierd problem
SimpleServlet.java:2: package javax.servlet does not exist
HTTP method POST is not supported by this url
Wierd problem