Java Servlet Barcode Generation Tutorial
How to generate barcode images in Java Servlet, JSP, J2EE Web Projects & Applications
Download Java Barcode Generator Free Evaluation
Purchase Java Barcode Generator SDK License
We found the Java Barcode an easy barcode solution for JasperReports.
- Gary Lipkowitz, USA

Creating, streaming linear & 2D barcodes in Java Web Applications

  • Compatible with JDK 1.4.2 and above versions
  • Support any operating system with Java Virtual Machine for barcoding
  • Java Servlet included to stream & display barcodes in Java server-side application
  • Java sample codes are available to print valid bar codes using Java Servlet Class programming
  • Support Apache Tomcat or JBoss to insert png, jpg, gif, tiff, eps barcodes in html code
  • Complete functions to easily adjust barcode settings like size, resolution, image format
  • Also used to quickly print barcode pictures in Jasper Report, iReport, and Oracle Report
  • Auto algorithm for calculating & displaying checksum digit under barcode image via Java language
  • Reliable and easy-to-use Java barcode library (jar) with free trial package download
This Java Barcode Control Generator provided by OnBarcode is a professional Java barcode library SDK, which combines all the 30+ barcode types (linear & two-dimensional) into a sing JAR file. This Java library plugin supports various Java applications including JSP Servlet, Java Class Library, Reporting - Eclipse BIRT, etc. With this advanced barcode implementing device, developers can easily integrate best barcodes into html, websites with Java code or URL for all web browsers.
Besides Java Servlet tutorial, we also provide other Java based barcode implementation how-tos:
  1. Java Barcode Library Guide - Examples to create & retrieve barcode symbology in various Java applications & programs
  2. Java Class Barcode Guide - Examples to implement multiple barcode labels of good quality in Java Class Library
  3. iReport Barcode Guide - Examples to programmatically print & embed bulk alphanumeric barcode images in iReport
How to Create Barcode with Apache Tomcat using Java Servlet
  1. Install or verify your use of JDK 1.4.2 or above
  2. Unzip the trial, copy the barcode folder and its contents your Apache Tomcat webapps file
  3. Restart Apache Tomcat server by restarting the service
  4. Navigate to this URL to generate a barcode: http://localhost:8080/barcode/barcode?DATA=0123456789&TYPE=CODE128
  5. You can specify parameters in the URL to adjust barcode type and image settings
  6. You can insert barcode images in HTML / web page with image tag, using the barcodes created in Java Servlet:
    <img src="http://localhost:8080/barcode/barcode?DATA=0123456789&TYPE=CODE128" />
How to Print Barcode Image in Java Servlet Class
OnBarcode also provides specific guide to encode barcode data, or customize barcode image:
  1. Sample code for Barcode Data Encoding - Creating GS1-Compatible Barcodes or encode Unicode into Java Barcodes
  2. Sample code for Barcode Image Setting - Generating barcodes in Java and adjust barcode image properties
Presented below is the simple Java api sampel code for printing barcode images in Java Servlet application. Copy the demo syntax to your program for barcoding. Code 128 encoding numeric string value is used as an example. For other input or special character text, please change the Java syntax for other barcode type.

import com.onbarcode.barcode.AbstractBarcode;
import com.onbarcode.barcode.Code128;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;

public class BarcodeServlet extends HttpServlet
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException
try {
Code128 barcode = new Code128();

// Basic barcode size settings here

//Customize barcode image format into Gif(0), Jpeg(1), and Png(3)

// Set generated barcode image resolution

// Set barcode rotation rate. 0 degree(0), 90 degree(1), 180 degree(2), 270 degree(3)

ServletOutputStream servletoutputstream = response.getOutputStream();

response.setHeader("Pragma", "no-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);

// Generate Code-128 barcode & output to ServletOutputStream

} catch (Exception e) {
throw new ServletException(e);
Java Barcode Generation Guide for Linear & 2D Barcode Types

Java Barcoder Library SDK - Barcodes Generation

OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © . All rights reserved.