creating login screens using jsp,servlets and oracle 9i

Discussions

Web tier: servlets, JSP, Web frameworks: creating login screens using jsp,servlets and oracle 9i

  1. Hi all, I'm using the following, netBeans 5.0, Oracle 9i. I was trying to create a login screen using jsp and servlets. Here is the flow, index.jsp(click on submit button after entering username and password) >> load the WelcomeServlet >> The WelcomeServlet will call another class which has the database connection and the username and password validation with the database table stored in oracle 9i. Once hte username and password is correct then it will load the welcome.jsp page... shown below is exactly what I did....Please help me with this as I'm totally lost on how to proceed furthur. 1) The index.jsp file... username password 2)The WelcomeServlet public class WelcomeServlet extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("Text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println(""); out.println("Welcome"); out.println(""); out.println(""); out.println("Employees Welcome!!!!"); out.println("

    "); String user = request.getParameter("userid"); String pass = request.getParameter("password"); DbConnection dbconn = new DbConnection(); try{ if(DbConnection.validateUser(user, pass)){ out.println("
    Jothi" + DbConnection.validateUser(user, pass)); out.println("Sorry you are not authorized"); } } catch(Exception e){ e.printStackTrace(); } out.println(""); out.println(""); out.println(""); } Finally 3) The DB connection class, public class DbConnection { public Connection getConnection() throws IOException{ Connection conn = null; try{ Class.forName("oracle.jdbc.driver.OracleDriver"); conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:ORCL", "scott", "tiger"); } catch(SQLException e) { System.out.println("SQLException: " + e.getMessage()); while((e = e.getNextException()) != null) System.out.println(e.getMessage()); } catch(ClassNotFoundException e) { System.out.println("ClassNotFoundException: " + e.getMessage()); } return conn; } public static boolean validateUser(String user, String pass) throws SQLException, IOException{ String Username = null, Password = null, returnstring=null; DbConnection dbconn = new DbConnection(); Statement stmt = dbconn.getConnection().createStatement(); String sql = "SELECT USER_NAME, PASS_WORD FROM LOGIN" + "WHERE USER_NAME='" + user + "'" + "AND PASS_WORD='" + pass + "'"; ResultSet rs = stmt.executeQuery(sql); if(rs.next()){ Username = rs.getString("USER_NAME"); Password = rs.getString("PASS_WORD"); } if(Username != null && Password != null && user.equals(Username) && pass.equals(Password)){ return true; } else return false; } } Please people who know this kindly reply me with possible solution.

    Threaded Messages (2)

  2. Wrong param[ Go to top ]

    I have not read your post carefully but on the first sight there is an inconsistency between: in your jsp and request.getParameter("userid"); in your servlet
  3. Hi dennis[ Go to top ]

    Thanks for your comments...I accept that I made a mistake but now it is working fine....anyways thanks for your comments...