DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Electron Js + jQuery + Bootstrap - Dev to Build
  • Validate XML Request Against XML Schema in Mule 4
  • Validate JSON Request Against JSON Schema in Mule 4
  • DevSecOps: Enhancing Security With Vulnerability Scanning of Images and Source Code in CI/CD

Trending

  • Automated Testing Lifecycle
  • Automated Testing: The Missing Piece of Your CI/CD Puzzle
  • Revolutionizing Software Testing
  • Spring Authentication With MetaMask
  1. DZone
  2. Coding
  3. Frameworks
  4. How to create a JQuery DataTable using JSON and Servlet

How to create a JQuery DataTable using JSON and Servlet

Nitin Kumar user avatar by
Nitin Kumar
·
Aug. 27, 13 · Tutorial
Like (1)
Save
Tweet
Share
89.20K Views

Join the DZone community and get the full member experience.

Join For Free

in this article i’ll introduce the basic coding that require to create jquery datatable using json passed by simple servlet.
datatable is very powerful jquery based grid with advance features which can be build in short span of time with customize features.

installation
1. download latest jquery datatable download
2. above download will provide two jquery plugin jquery.js and querytables.js

<script type="text/javascript"
charset="utf-8" src="/datatables/media/js/jquery.js"></script>
<script type="text/javascript"
charset="utf-8" src="/datatables/media/js/jquery.datatables.js"></script>

3. default stylesheet which shipped with latest datatable download package

<style type="text/css" title="currentstyle">
@import "../resources/css/demo_table.css";
</style>

note: you can download full source code from github link

creating the datatable

we can write below code to create the basic datatable with data

feedsummary.jsp
==========================

<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var otable = $('#tableid').datatable( {
"processing": true,
"ajax": {
"url": "/feedsummaryupdate/feedservlet",
"datasrc": "demo",
"type": "get"
}
} );
} );
</script>

$(document).ready will ready to execute the javascript and var otable = $(‘#tableid’).datatable says that write datatable on tableid place.

datatables will adding sorting, filtering, paging and information to your table by default, providing the end user of your web-site with the ability to control the display of the table and find the information that they want from it as quickly as possible.

the pointer tableid and column name will be defined in table tag as below

feedsummary.jsp
=====================

<table cellpadding="0" cellspacing="0" border="0"
id="tableid">
<thead>
<tr>
<th width="10%">first name</th>
<th width="10%">last name</th>
<th width="10%">address 1</th>
<th width="10%">address 2</th>
</tr>
</thead>
</table>

above datatable code invoke feedservlet which will return json string as defined below

feedservlet.java
===============

protected void dopost(httpservletrequest request,
httpservletresponse response) throws servletexception, ioexception {
printwriter out = response.getwriter();
string json = "{ \"demo\":[[\"first name\",\"last name\","+
+\"address1\",\"address2\"],[\"first name\",\"last name\",\"address1\",\"address2\"]]}";
out.println(json);
}

now either we can use servlet annotation or web.xml as below to register above feedservlet

web.xml
=========

<servlet>
<description></description>
<display-name>feedservlet</display-name>
<servlet-name>feedservlet</servlet-name>
<servlet-class>feedservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>feedservlet</servlet-name>
<url-pattern>/feedservlet</url-pattern>
</servlet-mapping>

running

incorporate the above point and deploy with server to view the result as follows:

http://localhost:8080/exampledatatablejson/feedsummary.jsp

jquery datatable image

jquery datatabl

conclusion
you can download full source code from github link and most welcome to fork or update the same.

references:

http://datatables.net/examples/

JQuery JSON

Published at DZone with permission of Nitin Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Electron Js + jQuery + Bootstrap - Dev to Build
  • Validate XML Request Against XML Schema in Mule 4
  • Validate JSON Request Against JSON Schema in Mule 4
  • DevSecOps: Enhancing Security With Vulnerability Scanning of Images and Source Code in CI/CD

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: