• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

authentication page

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, can anyone help me with this code i'm new in programming, when i try this code it always prompt me "You are not an authentic person" but the user name and password that i use to login is correct, can somebody help to check where can i go wrong

here is the jsp file Authentication.jsp



here is the servlet Authentication.java



here is my web.xml


need help really really need help
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2 suggestions:
  • Ask a question. I do not know if you are having a problem with your JSP, your servlet, or your web.xml file. Or whether your problem is unrelated to any of these - perhaps it is a JDBC issue, or an SQL issue. You have not said what exactly you would like help with
  • UseCodeTags (click the link to find out more). Please click the button to go back and edit your post and add the code tags.
  •  
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    1) For starters log the values of password and username that you have retrieved from the database. They are an obvious mismatch from the input values thats why you are not being authenticated.

    2) You are retrieving all the rows from your database table. Which means that even if your password and username is correct but there are more than one sets of correct username's and passwords your program has a high chance of not working.
    So retrieve a row using the specific username in the WHERE clause. It will help.

    3) Also preferred is that you should log the values you have retrieved from the request scope by first reading them into a string variable.
     
    roy ramos
    Greenhorn
    Posts: 26
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Sir Aditya,

    I only have 1 entry on my testing database
     
    Bartender
    Posts: 6663
    5
    MyEclipse IDE Firefox Browser Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    What is the user name and password you get from the request ? Log it

    What is the user name and password you get from the database ? Log it

    Compare both. Of course you will have to remove the logs after you are done
     
    Aditya Keyal
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Also can you check the server logs. I have a feeling your database call might be failing but is getting caught in the catch-block and absorbed. Check your server logs first to confirm if you have any errors.
     
    Andrew Monkhouse
    author and jackaroo
    Posts: 12200
    280
    Mac IntelliJ IDE Firefox Browser Oracle C++ Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    First some general comments:

    You are not using the ServletConfig in the code you presented - while not causing a problem, it is generally considered a good thing to only have the minimum code needed to solve your problem (or to demonstrate your problem).

    The code:is creating a new String object on a static String object. So at the end of running those lines of code, you will have 3 instances of the "" string - not very efficient. For your purposes, you could get away with

    You are potentially leaking connections to your database since you are not closing the Connection you have created. In addition, if there is any exception in any part of your code you will potentially also leak the ResultSet and the Statement. You should change the logic to use a try...catch...finally block. For example:

    Side note: most people who are dealing directly with databases like this (rather than using a framework), tend to have a utility class that has methods for each of these, such as "closeResultSet", "closeStatement" and "closeConnection". They often also have multiple overriden "close" methods that then close whatever they are passed, even if they are passed multiple objects and/or alternating orders of objects.

    You might also want to think about whether you really want to be opening and closing your connection (and loading your JDBC driver) every time you process a user request - lines 21,22,24,25,29 and 31 might be better in your init method (and loading the database configuration details based on the ServletConfig is generally considered a good thing).

    In the code I showed above I have followed your convention of sending error information to standard out and standard error. This is not a good idea - depending on how your system is configured you may not ever see it. You really should learn to use the logger and send your log message to a guaranteed location.

    I suspect that the problem is with your database code, not your web based code. You could test this quite easily by changing your doPost method to work without DB connectivity. For example:

    See if you can login with the hard coded credentials there. If you can, then the problem is in the database code, and we can address that separately.
     
    roy ramos
    Greenhorn
    Posts: 26
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    first of all thank you very very much for all of you who respond to this topic

    Sir Andrew, i tried you're hard coded credentials and it able to proceed successfully
     
    Aditya Keyal
    Ranch Hand
    Posts: 71
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Good so that pretty much solves your problem. There is an error in the database retrieval of the username and password. Please look into the server logs, identify the issue and then go ahead and solve it / log it in the correct forum.
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic