problems in the post methods in a Servlet

i have a form where i have two textfields with name user and password.

when i call the servlet by the method post. it goes to the if condition and then goes to sendRedirect(microsof) instead of (google).

what i wanted was if the textfield have the value sy goes to google website.

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

{

String user2[] = request.getParameterValues("user");

String password2[] = request.getParameterValues("password");

String google = "http://www.google.com/";

String microsoft = "http://www.microsoft.com/";

if(user2.equals("sy") && password2.equals("sy"))

{

response.sendRedirect(google);

}

else

{

response.sendRedirect(microsoft);

}

how can i fix this problem?

regards

[894 byte] By [Christiana] at [2007-10-2 6:39:23]
# 1
You appear to be comparing a String array to a String constant. An array isn't a String so the comparisons will never be true. Did you mean to compare the first entry in those arrays?
DrClapa at 2007-7-16 13:47:34 > top of Java-index,Java Essentials,Java Programming...
# 2
yeahuser in the form has the value of "sy" and password also.how can i compare in the condition? as an array
Christiana at 2007-7-16 13:47:34 > top of Java-index,Java Essentials,Java Programming...
# 3

Next time you post a code, use code tags to format them.

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException{

// > i have two textfields with name user and password

// String user2[] = request.getParameterValues("user");

String user = request.getParameter("user");

// String password2[] = request.getParameterValues("password");

String password = request.getParameter("password");

String google = "http://www.google.com/";

String microsoft = "http://www.microsoft.com/";

// if(user2.equals("sy") && password2.equals("sy")){

if(user.equals("sy") && password.equals("sy")){

response.sendRedirect(google);

}

else{

response.sendRedirect(microsoft);

}

}

You don't need to use getParameterValues because there seems to be no multiple values

for each of your parameter name.

hiwaa at 2007-7-16 13:47:34 > top of Java-index,Java Essentials,Java Programming...
# 4

public void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException

{

String user[] = request.getParameterValues("user");

String password[] = request.getParameterValues("password");

String google = "http://www.google.com/";

String microsoft = "http://www.microsoft.com/";

String user2 =" ";

user2 = user2 + user;

String password2 = " ";

password2 = password2 + password;

if(user2.equals("sy") && password2.equals("sy"))

{

response.sendRedirect(google);

}

else

{

response.sendRedirect(microsoft);

}

}//end of doPost

Christiana at 2007-7-16 13:47:34 > top of Java-index,Java Essentials,Java Programming...
# 5
> user2 = user2 + user;What in the hell are you going to do by adding a string to an array?
hiwaa at 2007-7-16 13:47:34 > top of Java-index,Java Essentials,Java Programming...