• Post Reply Bookmark Topic Watch Topic
  • New Topic

Variable is not getting transferred from controller servlet to model

Arati nargide
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am accepting username and password from user and comparing it with database value.
Here is my controller code ----->

And I have created database connection in model and fetching password according to the username entered by user.
Here is my model ----->

Both controller and model are in the same package.
But either model is not receiving the username or it is not getting executed at all..... I am not able to find out the error..
Please help..
Jeanne Boyarsky
author & internet detective
Posts: 36003
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding a debug statement. In particular both before and after rs.next so you can see what it gets up to.

Also a few learning notes before you take this into the real world:
  • Use a PreparedStatement - search for SQL Injection to read about what someone can do with your code
  • Include the password in the database query's prepared statement so you aren't passing in around
  • Encrypt the password
  • Close your database resources in a finally block so you don't run out of connections
    Karn Kumar
    Ranch Hand
    Posts: 153
    Eclipse IDE Java Tomcat Server
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Arti,

    Seems you are new in the Java and have written good modularized code though some more modifications need to do .

    Follow what Jeanne has suggested.

    One very minute mistake i am observing is your servlet don't have doGet() or doPost() methods which is very important to get data from your request .

    See what exactly happens is when you are submitting the form having method="get" or "post" then all form parameters/data goes to your request and then to the servelet method doGet() or doPost() where you can process request data.

    So you need to add doGet() or doPost() method based on your form method and then can processRequest() from it .

    Please refer the below link for more details


    - Chetan
    What are you doing? You are supposed to be reading this tiny ad!
    the new thread boost feature brings a LOT of attention to your favorite threads
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!