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
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

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Electron Js + jQuery + Bootstrap - Dev to Build
  • Server-Driven UI: Agile Interfaces Without App Releases
  • Why Whole-Document Sentiment Analysis Fails and How Section-Level Scoring Fixes It
  • Online Developer Tools a Backdoor to Security Threat

Trending

  • Docker Model Runner: Running AI Models Locally Made Simple
  • Software Specs 2.0: An Elaborate Example
  • The Battle of the Frameworks: Choosing the Right Tech Stack
  • When Incentives Sabotage Product Strategy
  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

By 
Nitin Kumar user avatar
Nitin Kumar
·
Aug. 27, 13 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
89.9K 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
  • Server-Driven UI: Agile Interfaces Without App Releases
  • Why Whole-Document Sentiment Analysis Fails and How Section-Level Scoring Fixes It
  • Online Developer Tools a Backdoor to Security Threat

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

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

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: