tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Lee" <tech_supp...@uls.com>
Subject Re: Servlet running twice at the same moment.
Date Wed, 02 Jan 2002 19:12:19 GMT
Well, that depends on which code you would like to see?  The login code is
pretty basic...

Here's is my validateLoginServlet...
I am using a type4 jdbc driver (thinweb.tds driver).

import Common.dbfiles.*;

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

public class ValidateLoginServlet extends HttpServlet
{
 public void service(HttpServletRequest req, HttpServletResponse res)
            throws IOException
 {
  String errorCode = "";

  try
  {
   // get a connection
   Class c = Class.forName("com.thinweb.tds.Driver");
   Connection dbConn =
DriverManager.getConnection("jdbc:twtds:sqlserver://[removed];user=[removed]
;password=[removed];TDS=7.0");
   // instantiate data objects
   DBCustomersSet customersSet = new DBCustomersSet(dbConn,"Customers");
   //DBCustomers customers = new DBCustomers();

   // Now set the where clause to get the member (using setFilter)
   customersSet.setFilter("LoginID='" +
        req.getParameter("LoginID") + "'");

   Vector customersQuery = customersSet.query();
   //Create a session.
   HttpSession session = req.getSession(true);
   //Now let's see if any records were returned.
   if (customersQuery != null && !customersQuery.isEmpty())
   {
    customersSet.firstRecord();

    //DBCustomers cust = (DBCustomers) custSet.record();
    DBCustomers theCustomer = (DBCustomers) customersSet.record();
    //DBCustomers theCustomer = (DBCustomers)customersQuery.elementAt(0);

    //Now we want to check the password.
    if (theCustomer.getPassword().equals(req.getParameter("Password")))
    {
     session.setAttribute("theCustomer",theCustomer);
     errorCode = "0";
     System.out.println("UserID: " + theCustomer.getLoginID() +
       " has logged in.");
     customersSet.userLoggedIn();
    }
    else
    {
     //Wrong password, set the errorCode to 1.
     errorCode = "1";
    }
   }
   else
   {
    //Not found, set the errorCode to 2.
    errorCode = "2";
   }
   session.setAttribute("errorCode",errorCode);
   //System.out.println("ValidateLoginServlet errorCode: " + errorCode);
   dbConn.close();
  }
  catch (SQLException sqle)
  {
   System.out.println("Sql Exception: " + sqle);
  }
  catch (ClassNotFoundException cnfe)
  {
   System.out.println(cnfe);
  }
  catch (ArrayIndexOutOfBoundsException aioobe)
  {
   System.out.println(aioobe);
  }
  }
}

In this case, it shows "userid has logged in".  At times it will do it just
once, but other times it will do it twice... Did i add something in here
that shouldn't be?

Thanks.
----- Original Message -----
From: "Micael Padraig Og mac Grene" <caraunltd@harbornet.com>
To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
Sent: Wednesday, January 02, 2002 11:50 AM
Subject: Re: Servlet running twice at the same moment.


> At 12:00 PM 1/2/02 -0700, you wrote:
> >Hello,
> >
> >I don't know why this is happening, but... It seems like whenever I run a
> >single servlet, there are times it will run twice.  As in, this...
> >...Robin
>
> Robin, there is no way to have any clue why this is happening without
> seeing the code. Micael
>
>
> --
> To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
> For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
> Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


--
To unsubscribe:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands: <mailto:tomcat-user-help@jakarta.apache.org>
Troubles with the list: <mailto:tomcat-user-owner@jakarta.apache.org>


Mime
View raw message