Datatables server side processing in Java

This post explains implementing datatables server side processing in java. Check out Datatables with Spring MVC example from my previous blogs to understand in details. In this post I will be explaining server side processing on datatables, that is loading data on demand in datatable using AJAX.

The final structure of our application will be like –

Datatables Server side processing

Database Table Structure

Following data is already available in table “students“.

Datatables Server Side Processing

tableStructure

Step 1: Create a Dynamic Web Project and add dependencies and jars in the project’s lib folder present in WEB-INF folder. Here we will need two additional jars apart from Spring jars – mysql connector jar and json-object jar.

Datatables Server Side Processing

libFolder

JSP View Pages

Step 2: Create welcome.jsp page and myDatatables.jsp page

In the above JSP, we have added an ajax callback in the data table initialization code. This means while initialization of data table an ajax call will be sent to the controller (loadServerSideData.do) to fetch the data to be loaded in Data Tables. Please make a note, only required data will be fetched and not the complete data.

XML configuration files

Step 3: Configuration files will be –

Web.xml

dispatcher-servlet.xml

Controller, Service and DAO classes

Step 4: We will now add the controller class

Step 5: Now we will create the service method and its implementation.

Step 6: Lets create the DAO layer to get the connection object.

Output

Step 7: Your application is ready to run :). The output pages will be-

Datatable server side processing

output_welcome_page

Datatables Server Side Processing

ServerSideResponse

Datatables Server Side processing

ServerSideResponseExample

Hope this will help you.

DataTableWithSpring complete application.

Regards,

Nikhil Naoghare.

7 Comments

  1. free free

    thank you very much , it is easy to understand.

    Reply
    1. admin (Post author)

      Glad that this helped you. Thanks.

      Reply
  2. literateaspects

    Hi Nikhil,

    Can this same example also be re-created as a JSF application?

    Reply
  3. Literate Aspects

    Hello, do you have the same with JSF ?

    Reply
    1. admin (Post author)

      Sorry but I dont have it with JSP. However it wont be that difficult to convert this in JSF application if you get the basics right for JSF.

      Reply
  4. Sujit J

    Is there an example without the Spring MVC ?

    Reply
    1. admin (Post author)

      You can create the same exampled with simple JDBC as well. Instead of Spring framework you shall create the JDBC connection and get the data. Rest all functionality will be same.
      Anything else you want to know specifically?

      Reply

Leave a Comment

Your email address will not be published. Required fields are marked *