Helo Friends please help to me to make this code work properly.
this is the jsp page on which i retriving the data from table Userpassword to validate the user's "username and password"and
for this i uses the if else condtion and when i execute this code its always prints the else condition "Invalid Username" here is a code .

<%@ page import= "java.sql.*;"%>
<% Connection c=null;
      Statement st=null;
      DriverManager dm=null;
      ResultSet rs=null;
      PreparedStatement pt=null;
      String user="";
      String passu="";
      String url="Jdbc:Odbc:HelpDesk";
     String usr=null;
    String pas=null;
   String username=null;
String password=null; 
  username=request.getParameter("Username");
        password=request.getParameter("Password");
	
try
	{

   	  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	  c=dm.getConnection(url);
                pt=c.prepareStatement("select * from UserPassword");
	  rs=pt.executeQuery();
              while( rs.next())
	  {
	  pas=rs.getString(1);
	  usr=rs.getString(2);
	}
	
	
	if(usr.equals(username))
	{
	  if(pas==password)
	{
	RequestDispatcher rd=application.getRequestDispatcher("/Home.html");
	rd.forward(request,response);
	}
else
{
	out.println("Invalid Password");
}
}
else
{
	out.println("Invalid Username");
}
c.close();
}
catch(Exception e)
{
 	out.println(e);
}
%>
Comments
Wrong Forum, No Code tags, Not proper language...

Do not perform database manipulation directly from within scriplets, here is a tutorial how you should actually be going about performing database operations in web applications.

@neeraj

Do you take some pains to read about the forum where you post or you just start shooting ? If you would have cared to look around the forum you would have found that there was a forum for JSP too. Also there is an announcement encouraging the use of code tags for putting in code at the start of this forum, but I think following your habit you haven't looked for that either. Also you haven't seem to be attending too many English classes either, I would suggest you to use proper English with proper grammer and avoid the spelling mistakes, it's irritating to read.
BTW If you happen to find the JSP forum here, there is thread there that is useful for all JSP beginners, since you seem to be one.
Also there in that thread they have mentioned how bad a habit it is to make your database connections in the JSP page itself, read that too, since you have violated that convention too. I think the only last one that had remained to be violated.

Do you take some pains to read about the forum where you post or you just start shooting ? If you would have cared to look around the forum you would have found that there was a forum for JSP too. Also there is an announcement encouraging the use of code tags for putting in code at the start of this forum, but I think following your habit you haven't looked for that either. Also you haven't seem to be attending too many English classes either, I would suggest you to use proper English with proper grammer and avoid the spelling mistakes, it's irritating to read.
BTW If you happen to find the JSP forum here, there is thread there that is useful for all JSP beginners, since you seem to be one.
Also there in that thread they have mentioned how bad a habit it is to make your database connections in the JSP page itself, read that too, since you have violated that convention too. I think the only last one that had remained to be violated.

If you actually hit the button for "Flag Bad Post" there would be no need for all this!
Post already marked for move to JSP section...

If you actually hit the button for "Flag Bad Post" there would be no need for all this!
Post already marked for move to JSP section...

Yes I could do that, but then I just wanted to make him understand what all wrong things he had done and how easily he could have fixed them, which certainly couuld not have been done with the 'Flag Bad Post'
And I know he might continue with such stuff even after reading my post, but then it's his choice whether to take the advice, I have done my part.

This article has been dead for over six months. Start a new discussion instead.