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
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 >

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