Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Simple Login Servlet.

  • 09-03-2005 05:15PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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