0

I have a servlet that gets a parameter that tells it which operation to carry out.

in the servlet, i have if statements that check if the parameter is a certain number (1,2,3). I use getParameter to get the parameter as a string but somehow it does not go into the if statements. What am I doing wrong? Thanks.

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by masijade
0

The code might help.

However, marking your post as "URGENT" is extremely rude. Suggesting that your problem is more important than anyone elses and more important than anything we, ourselves, might be doing and so we should drop everything we're doing and concentrate on your problem. Well, I'm sorry, but it's not, for us, and marking it as such is only going to cause most people to look away from your problem, rather than help you with it.

0

I'm sorry.
This is the html input code:

<SELECT NAME="param">

<OPTION value = "2">2</OPTION>
<OPTION value = "4">4</OPTION>
<OPTION value = "6">6</OPTION>

</SELECT>

This is the servlet:

String theparam = request.getParameter("param");
if (theparam == "2"){
out.println("The param is two");
}
0

Do not use == to compare Strings. Use Strings "equals" method.

if ("2".equals(theparam)) {

The "2" is done first as this will avoid any possible NullPointerException.

Edited by masijade: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.