SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: JSP Problems

  1. #1
    SitePoint Member
    Join Date
    Mar 2002
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy JSP Problems

    I'm using JSP for my dynamic web page and i am working on the login screen so that when an invalid user logs in the go directly to the error page but when a registered user logs in they go to the first page which is called irishshareprices.jsp. The problem is that no matter if it's a registered user or not it's automatically going to the indexerror.jsp page.

    The following is the code i'm using:

    <%-- Import required Java Classes --%>
    <%@ page import="javax.servlet.*" %>
    <%@ page import="javax.servlet.http.*" %>
    <%@ page import="java.sql.*" %>

    <%
    String user = request.getParameter("username");
    String pass = request.getParameter("password");

    Connection con=null;
    Statement stmt=null;
    ResultSet rs=null;

    /*if ((user == null)||(pass == null))
    {
    response.sendRedirect("indexerror.jsp");
    }*/


    String queryText="SELECT * FROM User WHERE UserID = '" + user + "' AND Password = '" + pass +"'";

    try {
    //initialize the JDBC-ODBC bridge driver
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");

    //open a connection to the database
    String username = "";
    String password = "";
    con = DriverManager.getConnection("jdbcdbc:db",username,password);

    //execute the query
    stmt = con.createStatement();
    rs = stmt.executeQuery(queryText);
    } catch (Exception e) { }


    if ((user == rs.getString("UserID")) && (pass == rs.getString("Password")))
    {
    response.sendRedirect("irishshareprices.jsp");
    }
    else
    {
    response.sendRedirect("indexerror.jsp");
    }

    %>

  2. #2
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From what I remember you can not use == when comparing strings. You need to use the .equals() function!

    HTH,
    K.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2000
    Posts
    164
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are importing the wrong way

    <%@ page import="javax.servlet.*" %>
    <%@ page import="javax.servlet.http.*" %>
    <%@ page import="java.sql.*" %>

    should be

    <%@ page import="javax.servlet.*, javax.servlet.http.*, java.sql.*" %>

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2002
    Location
    UK
    Posts
    146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you are importing the wrong way

    <%@ page import="javax.servlet.*" %>
    <%@ page import="javax.servlet.http.*" %>
    <%@ page import="java.sql.*" %>

    should be

    <%@ page import="javax.servlet.*, javax.servlet.http.*, java.sql.*" %>
    eithne is not importing the wrong way as either way is valid, it is just a question of coding style.

    you can have as many import directives on a page as you want, see here for more info on the syntax for a page directive.

    the pointer kix gave regarding string comparison was most likely the problem.

    hope this clears things up
    Last edited by martm; May 7, 2002 at 14:09.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •