A Web Dynamic project on eclipse,
In a .jsp file I read the username and password from the user and called the logging function in the class below
The function should validate the username and password then redirect to to a different .jsp page
The redirection part below is Not working and has errors..
package myPackage;
import java.sql.* ;
import javax.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class javaMethods extends HttpServlet {
public String logging(String user_id, String password){
ResultSet request = null;
Statement stmt =null;
ResultSet rs = null;
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/users", "root", "maram");
stmt=conn.createStatement();
rs=stmt.executeQuery("SELECT * FROM usersData WHERE id = '"+user_id+"'");
if(rs.next()) //if username was found
{
if (rs.getString(2).equals(password))
{
if(rs.getString(3).equals("admin"))
{
////REDIRECTING///
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", "admin.jsp");
}
else
{
////REDIRECTING///
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", "welcome.jsp");
}
}
else //incorrect password
{
System.out.println ("Incorrect password");
}
}
else //user name does not exist
{
System.out.println ("Username does not exist");
}
}
}