Login system using a servlet

This is probably straight forward but I am a novice programmer and need help.

I am trying to develop a login for a web application, now I have attached my code used so far, essentially i connect to a oracle database with a table with my valid user names and passwords.
I also have a html form which POST's the username and password to the servlet.

How can I get my servlet to do a check to see and compare the data entered into the html form versus the data from the table (authorised username & passwords) and if they do it will lead onto the next html and if not it will go to a different page (error page).

I have posted the html page i using for login also, in case anyone wants to try it.
<html>
  <head>
  <title>Login Form</title>
  </head>
 
  <body>
  <H2>Please Login:</H2> 
  <FORM METHOD="POST" 
   ACTION="http://localhost:8080/StudentReg/servlet/mylogin" 
   name="myform"> 
  
  <BR>Username: <INPUT NAME="myusername">
  <BR>Surname: <INPUT NAME="mypassword">
  <BR><INPUT TYPE="submit" value="Submit Form"> 
  </FORM>
  </body>
</html>

Open in new window

mylogin.txt
bhessionAsked:
Who is Participating?
 
CEHJCommented:
0
 
CEHJCommented:
Authentication is built into the web container - in Tomcat it's realm-based. Which one are you using?
0
 
bhessionAuthor Commented:
Im using Tomcat and the eclipse IDE(I dont think that will matter but Im quite a novice here.).
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
bhessionAuthor Commented:
Im trying to avoid that way but I may have to go that way eventually. I modified some code that I found and I think im just missing something small.

Here is my new code and new html, Im missing something obvious.

I entered in a valid username and password from the table in the database but i tells me its invalid!
<html>
 <body>
  <H2>Please Login:</H2> 
  <FORM METHOD="POST" 
   ACTION="http://localhost:8080/StudentReg/servlet/LoginServlet" 
   name="myform"> 
  
  <BR>Username: <INPUT NAME="ID">
  <BR>Password: <INPUT NAME="PASS">
  <BR><INPUT TYPE="submit" value="Submit Form"> 
  </FORM>
  </body>
</html>

Open in new window

0
 
CEHJCommented:
>>Im trying to avoid that way

Why?
0
 
bhessionAuthor Commented:
Im trying to learn more about servlets
0
 
bhessionAuthor Commented:
Actually on reading that solution you posted a little closer, it seems to be the most logical way.
0
 
bhessionAuthor Commented:
Thanks, it was definitely worth looking at
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.