Home » Struts 2 Registration Form Example

Struts 2 Registration Form Example

by Online Tutorials Library

Struts 2 Registration Form Example

In this example, we are going to create a registration form using struts UI tags and store these information into the oracle database. You may use other database also such as mysql, DB2 etc. according to your requirement.

Let’s see the table first that we need to create in the oracle database.

It will be better for you to create an id for each user. To simply the example, we have not alloted any id with primary key enabled. But you can do it.


The steps to create the registration application in struts2 are as follows:

  1. Create input page (index.jsp)
  2. Create the action class (RegisterAction.java)
  3. Create the class to store data (RegisterDao.java)
  4. Map the request in (struts.xml) file and define the view components
  5. Create view components

1) Create input page (index.jsp)

It is the simple jsp page that uses struts 2 UI tags to create a form to get input from the user.

index.jsp


2) Create the action class (RegisterAction.java)

This Action class has five fields and one execute method. As we know, struts framework creates instance of the action class per request, we are passing this object in the save method of RegisterDao class.

RegisterAction.java


3) Create the class to store data (RegisterDao.java)

This class gets information from the object of RegisterAction class and stores these information in the strutsuser table.

RegisterDao.java


4) Map the request in (struts.xml) file and define the view components

This xml file contains information about the package, action class and view components.

struts.xml


5) Create view components

Here, we are creating two view components register-success.jsp and register-error.jsp.

register-success.jsp

register-error.jsp

You may also like