Login Example using Servlet, JSP, MySQL and Hibernate Framework.

In this example we are seeing how to develop Registration and Login application using technologies Servlet, JSP, Hibernate Framework and MySQL Database. This application is developed using eclipse IDE. Using Hibernate Framework developer no need to create table in DB, Hibernate framework will take care about creating table. Just developer need to configure DB schema details like username, password, URL (DB TNS entry) and Driver name in the configuration file, named as hibernate.cfg.xml file. and we need to create mapping file with java entity class to Table name and entity properties names to table column names.
i.e, mapping object oriented data to relational data.

Below find the Test Case and flow of the application.























To run the application below Jar file required in lib folder of the application as per the standards of Java Organization.
Below Jar files are available with Hibernate framework. (for more clarification see the previous post: Click Here)
  • antlr-2.7.7.jar
  • cdi-api-1.1.jar
  • classmate-1.3.0.jar
  • dom4j-1.6.1.jar
  • el-api-2.2.jar
  • geronimo-jta_1.1_spec-1.1.1.jar
  • hibernate-commons-annotations-5.0.1.Final.jar
  • hibernate-core-5.2.4.Final.jar
  • hibernate-jpa-2.1-api-1.0.0.Final.jar
  • jandex-2.0.0.Final.jar
  • javassist-3.20.0-GA.jar
  • javax.inject-1.jar
  • jboss-interceptors-api_1.1_spec-1.0.0.Beta1.jar
  • jboss-logging-3.3.0.Final.jar
  • jsr250-api-1.0.jar
Below 2 .jar files are available with Tomcat Server (under %Tomcat_Home%/lib folder)
  • servlet-api.jar
  • jsp-api.jar
Below mysql-connector-java-5.1.37-bin.jar file is available with MySQL instillation (under  %MySQL_initialization_location%\Connector.J 5.1\ folder) or available in maven repository.
  • mysql-connector-java-5.1.37-bin.jar
Note: MySQL mysql-connector-java-X.X.X-bin.jar version file is different from MySQL version to version.
For developing application using eclipse IDE software, create a Dynamic web project and create the project structure like below screen short.



User.java is the DTO object, means this is the Data Transfer Object between the application layers. from Controller layer to Service layer, Service layer to DAO Layer etc....
User.java
Below .xml file is the configuration file between the Hibernate framework and MySQL DB, based on the below configuration hibernate create a Table in MySQL DB.
User.hbm.xml
hibernate.cfg.xml :
It is an .xml file, in which DB connection details like username, password, url and Driver Class name etc... & hibernate properties like Dialect, show_sql and hbm2ddl.auto etc....
hibernate.cfg.xml You know very well every Java web application must have deployment descriptor configuration for application (either .xml or annotation configuration), below is the web.xml file for our application.
web.xml
In above web.xml file configured welcome file as a login.jsp page and Servlet class with urls login, registration. here Servlet class are controllers for this application. see the below two controllers.
LoginController.java
RegistrationController.java
Below are the Service declaration and Implementation Classes
BaseService.java
BaseServiceImpl.java
Below are the Dao Declaration and Implementation Classes
BaseDao.java
BaseDaoImpl.java
Hibernate Utility Class for Application. Using this class creating Hibernate connection and using this connection in Application Dao Implementation class
HibernateUtil.java
login.jsp
userRegistration.jsp
home.jsp
Login Example using Servlet, JSP, MySQL and Hibernate Framework. Login Example using Servlet, JSP, MySQL and Hibernate Framework. Reviewed by Gurugubelli Technologies on January 30, 2017 Rating: 5

36 comments:

  1. Bonjour, tout d'abord je vous remercie pour le code bien détaillée. J'ai testé le code mais lors de run de userRegistration un message d'erreur la ressource n'est pas disponible.
    Merci d'avance

    ReplyDelete
  2. Hello Gurugubelli,
    This walk-through was great help! Thank you! Like Olfa mentioned there was an issue with the UserRegistration portion, the fix to this is to update the web.xml page to have

    UserRegistration
    /userRegistration


    Regards,
    Jon

    ReplyDelete
    Replies
    1. ***Update***
      url-pattern for the UserRegistration servlet should be "/userRegistration" instead of "/registration"

      Delete
    2. Hi Jon,
      Thanks for your comment, I have updated the web.xml file.

      Delete
  3. the options such as deny, grant, enable and disable login status in SQL Server. It also explains which options to use when. liteblue usps gov login

    ReplyDelete
  4. tried the exact same code, on submitting getting 404

    ReplyDelete
  5. Hi Akshay
    404 error means, your requisted resource URL is not available. Please share me what URL you have requisting and also provide a log trace.

    ReplyDelete
  6. hi your userRegistration.jsp content same like login.jsp

    ReplyDelete
    Replies
    1. Hey Macix, userRegistration.jsp and login.jsp files have different content. Check once.

      Delete
  7. initialy what is the user name and pass word

    ReplyDelete
    Replies
    1. For accessing application first need a user registration and use the same credentials you have given at the time of registration.

      Delete
  8. HI Team,

    am able to see the login and i don't know the credentials

    ReplyDelete
    Replies
    1. I think don't have a default user for this application, First try to register a user your self and use the same credentials for accessing application :)

      Delete
  9. the userRegistration.jsp is same as login.jsp. please help.

    ReplyDelete
    Replies
    1. Hello Debdutta, both jsp files have different content, please check once

      Delete
  10. also login controller and registration controller are same.

    ReplyDelete
    Replies
    1. Hey Debdutta, Login and Registration controllers have similarity but having different business logic. I think you have missed this logic :)

      Delete
  11. hi, I'm receiving the following error message

    Exception occred while reading user data: Cannot open connection

    ReplyDelete
  12. Gowthaman19 June 2019 at 03:18
    hi, I'm receiving the following error message

    Exception occred while reading user data: Cannot open connection

    ReplyDelete
  13. The article is so appealing. You should read this article before choosing the Hadoop consulting services you want to learn.

    ReplyDelete
  14. i got error "id to load is required for loading".what i do?

    ReplyDelete
    Replies
    1. Same error I get.
      So what should I do?

      Delete
  15. where is struts.xml?
    kindly send me this file.

    ReplyDelete
  16. software testing company in India
    software testing company in Hyderabad
    Thanks for providing such a great blog with us about Login Example using Servlet, JSP, MySQL and Hibernate Framework.
    please keep sharing.

    ReplyDelete
  17. Gerçek bodrum bayan arkadaş ile görüşme gerçekleştirmek için Bodrum bayan arkadaş sayfasına giriş yapabilir, Bodrum bayan arkadaş ilaları inceleyebilirsin: bodrumbebekleri.com

    Bodrum bayan arkadaş ilanlarına göz gezdirmek için hemen bodrum bayan arkadaş sayfasına tıkla birbirinden gerçek bodrum bayan arkadaş profillerini görüntüle: bodrumbebekleri

    Bodrum bayan arkadaş sitesi olan Bodrumbebekleri ile sende hemen bir bodrum bayan arkadaş telefon numarasına ulaşabilirsin. Bodrum bayan arkadaş sayfasına giriş yapmak için tıkla: bodrum

    ReplyDelete
  18. You can order percocet online overnight shipping.These solutions are astonishing manufactured substances that change the working of the central tactile framework. When mishandled, they can provoke veritable repercussions, including enormous organ hurt, the improvement of a substance use issue, and even death in occasions of overabundance.
    Order oxycontin 80mg online
    Order dilaudid 8mg online
    Order Percocet 7-5mg online
    Buy oxycontin 40mg online
    Buy oxycontin 80mg online
    Buy Percocet 10-325mg online

    ReplyDelete
  19. I would like to say more thanks about what you have created here on your blog. It is really very informative and interesting. Do you have any idea about the requirements for Turkey visa. A little bit of change in the requirement of a Turkish visa . Check all the updates in one click and increase the chances of your visa approval.

    ReplyDelete

  20. خدمات نقل الاثاث
    The best furniture moving company in Riyadh and Al-Kharj from the Clean Corner is one of the large companies that are widely displayed, where you can get a group of high-level services significantly with prices outside the competition.شركة نقل اثاث بالرياض
    شركة نقل اثاث بالخرج

    ReplyDelete
  21. I think this is one of the most significant information for me. And i’m glad reading your article. But should remark on some general things
    출장샵
    출장샵
    출장샵
    출장샵
    출장샵
    출장샵
    출장샵

    ReplyDelete

Powered by Blogger.