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.

Recommended Answers

All 3 Replies

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.

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");
}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.