JSON-taglib is a set of JSP tag libraries used to output JSON-format data in JSP code.
JSON-taglib converts data formats using JSON: array, JSON: object, and JSON: property.
The specific usage is as follows:
Just dropJson-taglib.jarFile intoWEB-INF/libDirectory of your web-application.
Here's a quick example of how the taglib cocould be used with an Ajax e-commerce shopping cart. Check out the examples or the tutorial for full details of how to use the taglib.
Call method:
- <% @ Taglib prefix = "JSON" uri = "http://www.atg.com/taglibs/json" %>
- <JSON: Object>
- <JSON: property name = "itemcount" value = "$ {cart. itemcount}"/>
- <JSON: property name = "subtotal" value = "$ {cart. Subtotal}"/>
- <JSON: array name = "items" Var = "item" items = "$ {cart. lineitems}">
- <JSON: Object>
- <JSON: property name = "title" value = "$ {item. Title}"/>
- <JSON: property name = "Description" value = "$ {item. Description}"/>
- <JSON: property name = "imageurl" value = "$ {item. imageurl"/>
- <JSON: property name = "price" value = "$ {item. Price}"/>
- <JSON: property name = "QTY" value = "$ {item. qty}"/>
- </JSON: Object>
- </JSON: array>
- </JSON: Object>
Josn output result:
- {
- Itemcount: 2,
- Subtotal: "$15.50 ",
- Items :[
- {
- Title: "The Big Book of foo ",
- Description: "bestselling book of Foo by A. N. Other ",
- Imageurl: "/images/books/12345.gif ",
- Price: "$10.00 ",
- Qty: 1
- },
- {
- Title: "javascript pocket reference ",
- Description: "Handy pocket-sized reference for the Javascript language ",
- Imageurl: "/images/books/56789.gif ",
- Price: "$5.50 ",
- Qty: 1
- }
- ]
- }
Be sure to check out the examples or the tutorial for more information about how to use the taglib.
Official Website: http://json-taglib.sourceforge.net/