Skip to main content

Simple Login Application Using Spring MVC and Hibernate – Part 2

 I hope you have visited my part1 of my tutorial. Let’s see the steps for integrating hibernate framework into Spring MVC. Here I have used MySQL database. I have created one database called “springmvc” and created one table called “user” with userid, username, password fields.

 I have inserted some records into table like this.

Step 1: Creating User POJO class.

 We need to create a User POJO class for mapping user table. Ok let’s create it.

Step 2: Creating hibernate mapping xml file for user class.

 In hibernate we need to create hibernate mapping xml file for all domain class for mapping into corresponding database table. Instead of creating xml file you can use annotation for mapping domain class into database table. This is my mapping xml document created for mapping our user domain class into user database table.

Step 3: Creating authenticate service class.


 The method “verifyUserNameAndPassword” present in “AuthenticateService” class is used for  verifying the user name and password details against database table. It simply returns the boolean value.
  Very important one is, I am injecting object for “HibernateTemplate” via setter method. So It’s time for defining data source bean, hibernate properties bean, session factory bean , hibernate template bean and our service beans into applicationContext.xml file.

Step 4: Modifying applicationContext.xml.


 Here I have configured the beans that are related to hibernate as well as for our service class. Now we need to inject our service class into our controller and we need to call the “verifyUserNameAndPassword” method for verifying user credentials. So let’s see the steps for injecting our authenticate service class into login controller. 

Step 5: Modifying Login Controller.


 Here @Autowird annotation is used for injecting our service class into our controller.
 That’s all. We have completed our development. Let’s do testing. I have deployed this application into apache server. The result of the application is,


Comments

VPOWER said…
Hi

LoginApp-SpringMVC-Part2 on github is not available
Gnanasuriyan said…
VPOWER,
Refer the below link,

https://github.com/gnanasuriyan/Spring-Hibernate-MVC-Part2/tree/master/LoginApp-SpringMVC-Part2

Gnanasuriyan
Anonymous said…
thanks Bro!!!


when i am running u r application , after enter user name and password then hit submit button got this error.

please help me out..how can solve this error.

HTTP Status 404 - /WebApplication2/Login.spring/processCredentials
Unknown said…
Hello, I'm getting an injection related error when running your code. please help
SaaD said…
Hi dude, I found your tutorial/example very useful and your tutorial made lots of clarification about the concept specially part 1. But I have one complaint that you have explained part 1 very very clearly and never left any doubt to ask, but in tutorial 2 even this tutorial is very us full but it has not explained well specially Template concept. It would be great if you also had few word of explanation for these term.

Any way very very thanks for the tutorial.

I will be very great full if you would refer any good book for me, with little description and more examples.
Amjad said…
Thanks for the brilliant little tutorial however there is a small comment to be made.
Everytime I use my username and password, it shows the invalid credentials. After hours of research I found out that HQL doesn't support the query alias and as soon as I removed the alias, my application started running fine.
Thanks again.
Unknown said…
Am New to spring and hibernate. I tried your tutorial but am getting the null pointer exception in hibernate.find(query) !!!!

Wat could b the possible reason???
Pls help me

Thanks in advance
Unknown said…
Hi bro really thanks for your application.have one doubt,suppose i want to add another user with ID,USERNAME,PASSWORD and after that can i login by this user name and password means whether i can add many users i can and can i login with it..

praveen
Gnanasuriyan said…
Hi shibu,

This is simple and the application authenticates user when user name and corresponding password is matching with database records. So you will have to insert to many users in user table.
connectanjana@gmail.com said…
hi suriyan,

thanks for the tutorial. it is simple and easy-to-understand.

Anjana
Anonymous said…
same as one of the comment
when i submit it will give me erroe message like
HTTP Status 404 - /LoginApp-SpringMVC-Part2/Login.spring/processCredentials
Unknown said…
change the index,html form as below is works well

form action="Login.spring" method="post"


thank u
Unknown said…

at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:921)
at org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:1)
at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
... 38 more

when ever i login its give me invalid credential
Unknown said…
HTTP Status 404 - /LoginApp-SpringMVC-Part2/Login.spring/processCredentials
RAMKI said…
Yes. Even am getting the same HTTP Status 404 error

HTTP Status 404 - /LoginApp-SpringMVC-Part2/Login.spring/processCredentials

type Status report

message /LoginApp-SpringMVC-Part2/Login.spring/processCredentials

description The requested resource (/LoginApp-SpringMVC-Part2/Login.spring/processCredentials) is not available.

Please help us in resolving the error.

Thanks in advance.
virat said…
please upload a code to build simple form including signup,signin and sign out in springs using database..
Unknown said…
not working.....http error
Deepa said…
HTTP Status 404 - /LoginApp-SpringMVC-Part2/Login.spring/processCredentials

please help me how i can resolve this
UNKNOWN said…
It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.

Selenium Training in Chennai

Selenium Training in Bangalore
UNKNOWN said…
It has been simply incredibly generous with you to provide openly what exactly many individuals would’ve marketed for an eBook to end up making some cash for their end, primarily given that you could have tried it in the event you wanted.

java Training in Chennai

Java Training in Bangalore




veeraraj said…
thanks for sharing valuable information
Excelr Tuhin said…
I've read this post and if I could I desire to suggest you some interesting things or suggestions. Perhaps you could write next articles referring to this article. I want to read more things about it!
data science certification
Keerthi55 said…
Nice post..
https://www.kitsonlinetrainings.com/course/sap-grc-online-training
http://kitsonlinetrainings.com/course/linux-onliane-trining
http://kitsonlinetrainings.com/course/windows-server-online-training
360DigiTMG-Pune said…
Excellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites!
artificial intelligence course in pune
data science said…

I was basically inspecting through the web filtering for certain data and ran over your blog. I am flabbergasted by the data that you have on this blog. It shows how well you welcome this subject. Bookmarked this page, will return for extra. data science course in jaipur
Thanks for posting the best information and the blog is very helpful
ServiceNow Training in Chennai
You really make it look so natural with your exhibition however I see this issue as really something which I figure I could never understand.
Excellent Blog! I would like to thank for the efforts you have made in writing this post.
servicenow training and placement in hyderabad
Himani said…
Great Content. Looking forward for your next posts.

Financial modeling course
Tidschoen said…
Thank you for sharing!
Digital Anita said…
I did not have knowledge about such kinds of technical things before I have been through this blog. It's a level of your thoughts that I must appreciate. Keep posting. And also you can have look on Digital Marketing Courses in Abu Dhabi
riona said…
Well explained article shared with us. This will for sure helpful for developers. Keep it up.
Upgrade your skills with the Digital Marketing Courses in Delhi and start reading more about it. Digital Marketing Courses in Delhi
Anonymous said…
This comment has been removed by the author.
neharikagupta96 said…
Thanks for explaining Login Application Using Spring MVC and Hibernate. you described it so well with each and every small detail. It really helped me, and I was able to do it now easily.
Great content and nice blog thanks for sharing this with us.
It is really very helpful, keep writing more such blogs.
Do read my blog too it will really help you with content writing.
we provide the Best Content Writing Courses in India.
Best Content Writing Courses in India
Vikas said…
A very informative tech article on MVC architecture a prominent trigger-based query programming for best performance and serving efficiently to users. Great article. Thanks very much for sharing your great experience with us. I will wait for more informative article. Keep sharing. If anyone wants to learn Digital Marketing, Please join the newly designed curriculum professional course on highly demanded skills required by top corporates. For more details, please visit
Digital Marketing Courses in Austria
Melys said…
Such an informational and useful article. Thanks for sharing this post about Simple Login Application Using Spring MVC and Hibernate. You must have taken hours to write this article. For sure it will help more developers. Keep it up. We also provide an informational and educational blog about Freelancing. Nowadays, many people want to start a Freelance Career without knowing How and Where to start. People are asking:
What is Freelancing and How Does it work?
How to Become a Freelancer?
Is working as a Freelancer really a good Career?
What is a Freelancer Job Salary?
Can I live with a Self-Employed Home Loan?
What Kind of Freelancing Jobs are Skills are required?
How to get Freelance projects?
How Do companies hire Freelancers?
In our Blog, you will find a guide with Tips and Steps which will help you to take a good decision. Start reading and find out the Answers.
Ranvi singh said…
if you want to learn digital marketing, IIM SKILLS can be a great place to visit. The platform gives really excellent courses.
Digital marketing courses in Trivandrum

Popular posts from this blog

Getting key/value pair from JSON object and getting variable name and value from JavaScript object.

 Hi, I had faced one issue like this. I have an JSON object but I don't know any key name but I need to get the all the key and corresponding value from JSON object using client side JavaScript. Suddenly I wondered whether it's possible or not, after that I had done lot of workaround and finally got this solution. See the below example.    function getKeyValueFromJSON() {     var jsonObj =  {a:10,b:20,c:30,d:50} ;     for ( var key in jsonObj) {       alert( "Key: " + key + " value: " + jsonObj[key]);     }  }  In this example I have created the one json array as string, and converted this string into JSON object using eval() function. Using for-each loop I got all the key value from jsonObj, and finally using that key I got the corresponding value.  Finally I got the alert like this,    Key: a value:10    Key: b value:20    Key: c value:30    Key: d value:50  During this workaround I got one more idea, using this same way I got

Simple Login Application Using Spring MVC and Hibernate – Part 1

 I hope developers working in web application development might hear about MVC architecture. Almost all technologies provide support for MVC based web application development, but the success is based on many factors like reusable of the code, maintenance of the code, future adaption of the code, etc..,  The success of the Spring MVC is “ Open for extension and closed for modification ” principle. Using Spring MVC the developers can easily develop MVC based web application. We don’t need any steep learning curve at the same time we need to know the basics of spring framework and MVC architecture. The Spring MVC consists of following important components. 1. Dispatcher servlet 2. Controller 3. View Resolver 4. Model Spring MVC - Overview  The overall architecture of Spring MVC is shown here.  1. When “Dispatcher Servlet” gets any request from client, it finds the corresponding mapped controller for the request and just dispatches the request to the corresponding contro