Note: This Tutorial assumes that you have required knowledge for working with Spring Framwork, Spring MVC, JSPs, JSPs tags, Java Servlets, and Java Dynamic Web projects.
For being able to use Aspose APIs on Spring MVC, you will need to first download the Aspose APIs by using any of the following sources:
Once you finished configuring Aspose APIs with your project you can further look into AsposeAPI.java source came with this project for the Aspose APIs examples and usage.
Aspose has developed Tag Library for Aspose APIs (Initially for Aspose.Barcode) using on JSPs (Spring Java Web Projects)
You can look into working examples / usage of Aspose APIs tag library in the following JSP files from this project source code:
For using Aspose API Tag Library in your Spring MVC project you need to copy the following files into your Spring based Java project;
In AsposeAPIConfiguration.java you will specify URI for @RequestMapping attribute of Barcode image generation service in Controller as in Spring MVC you write request handling code inside Controller class method instead of creating Servlets and definig URI mappings in web.xml. Please look into AsposeAPIController.java and AsposeAPI.java files of this project for reference implementation of Aspose Barcode generation service.
Note: If you want to use Aspose API with other Java Web Based projects not with Spring MVC, you will need to create Servlet for Barcode API service or add handing into your existing Controller Servlet and specify the correct service URL in AsposeAPIConfiguration.java constants.
After configuring service URL and code writing for Barcode generation using Aspose.Barcode API inside Controller class. (or in Servlet in case of other MVC / Java Web based projects)
You can now display the Barcode image on JSPs.
But one thing more, before using getBarcodeURL tag, you will need to specify AsposeAPI.tld file location along with the namespace "aspose" on top of your JSP page as below:
<%@ taglib uri="/WEB-INF/tags/aspose/AsposeAPI.tld" prefix="aspose" %>
For Non Spring MVC web project (but still using Spring Core Framework) AsposeAPI.tld need to be configured inside deployment descriptor file web.xml as below:
<%@ taglib uri="/WEB-INF/tags/aspose/AsposeAPI.tld" prefix="aspose" %><taglib> <taglib-uri> http://www.aspose.com </taglib-uri> <taglib-location> /WEB-INF/tags/aspose/AsposeAPI.tld </taglib-location> </taglib>
Then you can use getBarcodeUrl tag for displaying Barcode image on your JSP as below:
<aspose:getBarcodeUrl symbology="QR" billAmount="${visit.billAmount}" var="barcodeUrl"/> <img src="${barcodeUrl}" alt="Sponsored by Aspose"/>
The tag getBarcodeURL need TWO input parameters, FIRST is for BarCode Symbology/Type i.e QR, Code128 that AsposeAPI (Aspose.Barcode) provides and the SECOND is for CodeText / BillAmount as input for generating Barcode image. See you also have to provide a variable name for URL returning (return parameter) that you will later use with <img> tag for displaying Barcode image.
Note: getBarcodeURL tag uses your provided configurations in AsposeAPIConfiguration.java and create appropriate URL that will return the Barcode image if invoked.