Javatpoint Logo
Javatpoint Logo

Struts 2 Fetching all records of a table

To fetch all the records, we have stored all the records in a collection (using List), and displaying the data of the collection using the iterator tag of struts2.

Here, we assume that you have a table in oracle database named user3333 that contains records. The table query is:

Example to fetch all the records of the table

In this example, we are creating 5 pages :

  1. index.jsp invoking action.
  2. Register.java for storing data of the table in the collection.
  3. User.java for representing table.
  4. struts.xml for defining the action and result.
  5. welcome.jsp for the view component to display records.

1) Create index.jsp for invoking action (optional)

This jsp page creates a link to invoke the action. But you can direct invoke the action class.

index.jsp

2) Create the action class

This action class contains ArrayList object as the datamember and execute method.

Register.java

3) Create the class to represent table

This is the simple bean class containing 4 fields.

User.java

4) Create struts.xml

This xml file defines action and result.

struts.xml

5) Create view component

It is the simple jsp file displaying the information of the user.

welcome.jsp
Next TopicStruts Quiz




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA