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
Anaja Metellus 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.
Amjadali Saiyed 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.
manoj kumar 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
shibu apps 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
Md Shahensha 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
Manoj Kumar 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..
Dhanalakshmi M said…
not working.....http error
sukere said…
Really an amazing post..! By reading your blog post i gained more information.
SEO MOBILE MARKETING
Deepa said…
HTTP Status 404 - /LoginApp-SpringMVC-Part2/Login.spring/processCredentials

please help me how i can resolve this
ijazz jazz 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
ijazz jazz 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




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 all the variable name and corresponding value from Java…

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 controller. The reque…