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