
Greetings and Warm Welcome to the World of Spring !!!
I generally get enthused only when I see something works right the first time. My intention was to create a simple “Login App” before getting deeper into Spring. I should thank so many hundreds of people who have posted so much material on Spring – without which I would not have been able to write this up. Thanks to Google and all those Spring Authors.
Now lets start our simple project by defining the requirements.
Requirements:
- A Login page for a user to provide Username and Password
- Receive the provided User Credentials
- Validate the provided User Credentials
- Show Error Message in the Login Screen if the validation fails
- Show the Main Page if Validation is successful
First let us see “what” needs to be created. You can find the “why” for each of these by googling or in books.
I used Netbeans 6.1 and I hope you too have the same. Eclipse should work fine too – but I not verified that.
Step-1: under WEB-INF/jsp/ directory Create login.htm – with a form – form field names being “username” and “password”
Step-2: Create the Databean for this form. Call it Login.java. Define getter and setter methods for the fields “username” and “password” – these variables are case-sensitive and should be ditto as defined in login.jsp
Step-3: Create Controller for this Form – LoginController.java
Step-4: Create LoginValidator.java
Step-5: Edit web.xml
Step-6: Edit gspringapp-servlet.xml
a. Define bean = Login
b. Define bean id = validator
c. Define bean id = messageSource [For Error Message to be shown in the login page]
Step-7: Create message.properties under /WEB-INF/classes and make an entry - “key-value” pair. The key is the “name” given in “LoginValidator” for RejectValue
Step-8: Save spring.tld under /WEB-INF/jsp directory
Step-9: Create main.jsp and save under WEB-INF/jsp/ directory
###SOURCE FILES###
invalidLogin.login=Invalid Credentials-Username And Password Cannot Be Same
Hope with the above source, you were able to create a simple Login Application.
Cheers and Good Luck...
Ganesh Babu N R
0 comments:
Post a Comment