User Registration is basic need of any web application. This tutorial will give you a rough idea to create user sign in application. This user registration application can be easily integrated with any existing old application. User Registration is developed on Struts framework and follow MVC pattern. Application is containing three packages actions, model and util. actions package contains all those class which are action class of struts and formbean actionform classes. Model package contain all those classes which are used for logical part and business part. Util package contain only those classes to give helping to application, e.g. Database connection classes, closing object classes and properties file.

validation.xml is used for checking validate form value, if form is not validated properly it will throw error on user form.

validation.xml

<form-validation><formset><formname="registerform"><fieldproperty="emailid"depends="required,email"><msgname="required"key="errors.user.registration.email"/><msgname="email"key="errors.user.registration.email.valid"/></field><fieldproperty="password"depends="required"><msgname="required"key="errors.user.registration.password"/></field><fieldproperty="cpassword"depends="required,validwhen"><msgname="required"key="errors.user.registration.password.confirm"/><msgname="validwhen"key="errors.user.registration.password.match"/><var><var-name>test</var-name><var-value>(password==cpassword)</var-value></var></field><fieldproperty="firstname"depends="required"><msgname="required"key="errors.user.registration.first.name"/></field><fieldproperty="lastname"depends="required"><msgname="required"key="errors.user.registration.last.name"/></field><fieldproperty="gender"depends="required"><msgname="required"key="errors.user.registration.gender"/></field><fieldproperty="submitError"depends="validwhen"><msgname="validwhen"key="errors.user.registration.fail"/><var><var-name>test</var-name><var-value>((emailid!=null) and ((password!=null) and ((cpassword!=null) and ((firstname!=null) and ((lastname!=null) and (gender!=null))))))</var-value></var></field></form></formset></form-validation>

ApplicationResources.properties file is used for configuration and error

Most of web application today having login facilities. This tutorial is giving you a rough idea to develop login application for your application. This login application can be easily integrated with your old application. This login application is based on MVC pattern and build on struts framework. Application is containing three packages actions, model and util. actions package contains all those class which are action class of struts and formbean actionform classes. Model package contain all those classes which are used for logical part and business part. Util package contain only those classes to give helping to application, e.g. Database connection classes, closing object classes and properties file.

Steps to developing user login application

1. Create a project in eclipse

After creating a project in eclipse, now understand the flow of application.

UserAuthAction.java is action class of struts, this class authenticate user’s login and perform action according to the result. This is mainly use for user authentication.

validation.xml is used for checking validate form value, if form is not validated properly it will throw error on user form.

validation.xml

<form-validation><formset><formname="loginform"><fieldproperty="username"depends="required"><msgname="required"key="errors.login.name"/></field><fieldproperty="password"depends="required"><msgname="required"key="errors.login.password"/></field><fieldproperty="submitError"depends="validwhen"><msgname="validwhen"key="errors.login.fail"/><var><var-name>test</var-name><var-value>((username!=null) and (password!=null))</var-value></var></field></form></formset></form-validation>

ApplicationResources.properties file is used for configuration and error

Duplicate form submission results in saving duplicate data in database unnecessary. If you don’t want to save duplicate data in database, you need to prevent duplicate request to save in database. Action form get old request and save request object again in html form, and if user reload the page, it will save again and again in database.

Duplicate submission can be occur by refresh of page by user, pressing back button in browser, virus in user machine which resubmit form on every request.

Way to prevent duplicate request in Struts.

1. By handling isTokenValid() method of struts.

2. By handling clearing request object.

We are talking about clearing request object and creating new request for form.