Javadatabase login with Tomcat


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Javadatabase login with Tomcat

Hybrid View

  1. #1
    Join Date
    May 2007
    Posts
    5

    Javadatabase login with Tomcat

    Hi,

    I'm trying to create a website where users can upload partypics and such. Pretty lame idea but thats not the problem. I am trying to create a login page which checks in my database if the user name and the password is correct. However the problem is that everything works great with just one user name and password in my database, but as soon as another one registers no one can login.

    Here is my code.

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.DriverManager;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.DriverManager;
    import java.sql.Statement;

    import javax.servlet.*;
    import javax.servlet.http.*;

    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;


    public class LoggaIN extends HttpServlet {

    Statement stmt;

    ResultSet rs;

    Connection con;


    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

    String namn = request.getParameter("user");

    String losen = request.getParameter("password");





    try {


    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    con = (Connection) DriverManager.getConnection("jdbcdbc:databasen","","");
    stmt = con.createStatement();
    rs = (ResultSet) stmt.executeQuery("select UserName, Password from users");


    while(rs.next()) {



    if (!(namn.equals("null")) && (namn.equals(rs.getString("UserName"))) && (!(losen.equals("null")) && losen.equals(rs.getString("Password"))))

    {
    response.sendRedirect("inloggad.html");
    }


    else
    {
    response.sendRedirect("fel.html");
    }
    }

    }



    catch (Exception e) {
    e.printStackTrace();
    }



    }
    }





  2. #2
    Join Date
    May 2007
    Location
    Dell Rapids, SD
    Posts
    4
    It looks like you are redirecting the user if their name and password don't match the first one in the database. Move this line
    Code:
    response.sendRedirect("fel.html");
    outside of the while loop and get rid of the else clause. That should take care of it.

  3. #3
    Join Date
    May 2007
    Posts
    5

    It worked!!

    Yep, that did the trick! Thank you very much

Similar Threads

  1. Replies: 3
    Last Post: 01-26-2012, 02:16 AM
  2. Tomcat from Eclipse?
    By rongoe in forum Java
    Replies: 3
    Last Post: 08-01-2007, 09:46 PM
  3. login problem
    By dbrook007 in forum ASP.NET
    Replies: 0
    Last Post: 11-06-2006, 05:54 AM
  4. Tomcat eclipse configuration problem
    By sujiganne in forum Java
    Replies: 2
    Last Post: 04-07-2006, 07:39 AM
  5. Replies: 1
    Last Post: 02-27-2006, 04:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center