How to use Aspose APIs in Spring MVC and JSP pages.

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:

  1. Download directly from Aspose Components for Java
  2. -OR- Download using Aspose Wizard for Jetbrains plugin

Configuring Aspose APIs in your project:

  1. If you have configured your project as Maven project, please read our tutorial on integrating of Aspose API with Maven project.
  2. If your project is Java project or Web Based Java project, first create lib folder at the root of your existing project and copy downloaded Aspose APIs jars into it. You can then add Aspose APIs jars in your project class path.
  3. If you are creating new Java Project from scratch please refer to our Aspose Wizard Plugin for Jetbrains or Aspose Wizard Plugin for NetBeans Plugins for downloading and configuring Aspose APIs with Java Project more seamlessly.

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.

Using Aspose APIs on JSP page and Spring MVC controller:

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:

  1. createOrUpdateVisitForm.jsp
  2. ownerDetails.jsp

For using Aspose API Tag Library in your Spring MVC project you need to copy the following files into your Spring based Java project;

  1. AsposeAPI.java
  2. AsposeAPIConfiguration.java
  3. AsposeAPIController.java
  4. FieldPathParser.java
  5. AsposeAPIgetBarcodeUrlTag.java
  6. ScopedContext.java
  7. AsposeAPI.tld

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.

AsposeAPIConfiguration.java

 AsposeAPIController.java

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.

Aspose.Barcode Demonstration

 

Aspose.Barcode Demonstration

 

Note: getBarcodeURL tag uses your provided configurations in AsposeAPIConfiguration.java and create appropriate URL that will return the Barcode image if invoked.


 Recommended Links

Last edited Jun 19, 2014 at 9:55 AM by AdeelIlyas, version 5