954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

URGENT: need help with strings and getParameter

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.

glendavis
Newbie Poster
8 posts since Feb 2008
Reputation Points: 10
Solved Threads: 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.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

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");
}
glendavis
Newbie Poster
8 posts since Feb 2008
Reputation Points: 10
Solved Threads: 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.

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You