Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Simple Login Servlet.

Options
  • 09-03-2005 5:15pm
    #1
    Registered Users Posts: 3,012 ✭✭✭


    I've got a simple servlet that reads in a username and password from a html form and prints a string stating wether or not that username and password exists within my database.

    Problem is that it only gives the correct response on the first attempt, ie, every attempt after the first one returns the negative string, regardless as to wether or not the correct details were entered.

    Is there some sort of servlet command I need so that all the variables re-initiate with every attempt?

    Cheers.


Comments

  • Closed Accounts Posts: 1,651 ✭✭✭Enygma


    Have you got variables declared in the class scope?
    You probably need to reset all your variables to null in a destroy() method.
    public class LoginServlet extends HttpServlet
    {
       // I'm assuming you've got 
       String username;
       String password;
       // etc
    
       .
       .
       .
       public void destroy()
       {
          username = null;
          password = null;
          // etc
       }
    }
    

    Should do the trick.


  • Closed Accounts Posts: 24 colonelx


    Hi,
    its usually a bad idea to have class scoped variables when using servlets.

    Ensure that you only use method scoped variables.

    Eg:

    void doPost (.....){

    String name=request.getParameter("name");
    String pass=request.getParameter("pass");


    }


  • Registered Users Posts: 17,727 ✭✭✭✭Sherifu


    colonelx wrote:
    its usually a bad idea to have class scoped variables when using servlets.
    Ensure that you only use method scoped variables.
    Good advice, you could have synch issues for multiple servlet instances.


  • Registered Users Posts: 3,012 ✭✭✭BizzyC


    Got it, just had to move the code establishing my connection into the main doGet method.

    Thanks for the help.


Advertisement