Results 1 to 8 of 8
  1. #1
    Kelly is offline Member
    Join Date
    Mar 2010
    Posts
    7
    Rep Power
    0

    Default Creating sessions in java

    Hey, im trying to track if a user is logged in or not, ive made a login screen, which connects to a database and checks if the user exists, when if they exist, another window pops up, how can I check if the username exists without having to do another database query? Im not using servlets and when searching for examples those are the only ones im getting. Its not on a website, its a application.

    Anyone know how I would be able to do this?

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    if a user is logged in or not
    and
    not on a website , its a application
    It runs only on a user's PC without connection to the internet?
    how I would be able to do this
    What does a 'session' mean in the context of someone using a program on their own computer? Are there different people using this program on the same computer at different times?

  3. #3
    Kelly is offline Member
    Join Date
    Mar 2010
    Posts
    7
    Rep Power
    0

    Default

    At the moment I have two seperate Java files, one which acts as my client ( where the gui is) and another which is on another machine which acts as the server.

    the client java file, opens up a gui, gets the user input (username and password) then passes it to the server through sockets. The server part of the java file then creates a prepared sql query from the information username and password that was passed to it, and returns whether or not the user exists.

    These two java files are on different machines, different networks, that part works fine.

    If the client side recieves a "ok user exists" reponse, a second java gui opens up. What I was hoping to do was somehow protect the second gui from being accessed if a session isnt currently running, without having to do another database query to check if the username and password are still valid.

    Whenever i search for session examples I get heaps of ones for servlets, and httpsessions, which I dont think is what im looking for, if there are any other methods of doing this I would really appricate any suggestions :)

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    Session info can be keep by using cookies. The server adds a Set cookie to the HTTP response header field with a cookie that the server can use to maintain the status of a client. The next request from the client must return that cookie in its HTTP request header.
    The server would need a cookie management scheme.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    They're not talking http though, from what I can gather.

    OK, so you have a login screen...the user logs in...it's successful.
    How do you define "protect the second gui"? How do you think someone will get at the second gui without logging in?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    They need their own protocol taking the cookie idea from HTTP to preserve session state.

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,755
    Rep Power
    19

    Default

    Possibly, but since the whole gui seems to be on the client anyway it's not a very good match.

    Without actually knowing what they're up to I would be loathe to suggest mimicking a session setup.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

Similar Threads

  1. Kill sessions
    By Subscribe.name in forum Java Servlet
    Replies: 1
    Last Post: 10-05-2009, 10:22 PM
  2. Replies: 1
    Last Post: 10-01-2009, 01:51 PM
  3. java sessions
    By Raghuvasa in forum Advanced Java
    Replies: 2
    Last Post: 12-10-2008, 06:40 AM
  4. Sessions in jsp
    By Ed in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-02-2007, 03:46 PM
  5. sessions in jsp
    By Heather in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-30-2007, 03:44 PM

Posting Permissions

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