Output JSON format data in JSP code

Source: Internet
Author: User

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:

  1. <% @ Taglib prefix = "JSON" uri = "http://www.atg.com/taglibs/json" %>
  2. <JSON: Object>
  3. <JSON: property name = "itemcount" value = "$ {cart. itemcount}"/>
  4. <JSON: property name = "subtotal" value = "$ {cart. Subtotal}"/>
  5. <JSON: array name = "items" Var = "item" items = "$ {cart. lineitems}">
  6. <JSON: Object>
  7. <JSON: property name = "title" value = "$ {item. Title}"/>
  8. <JSON: property name = "Description" value = "$ {item. Description}"/>
  9. <JSON: property name = "imageurl" value = "$ {item. imageurl"/>
  10. <JSON: property name = "price" value = "$ {item. Price}"/>
  11. <JSON: property name = "QTY" value = "$ {item. qty}"/>
  12. </JSON: Object>
  13. </JSON: array>
  14. </JSON: Object>

Josn output result:

  1. {
  2. Itemcount: 2,
  3. Subtotal: "$15.50 ",
  4. Items :[
  5. {
  6. Title: "The Big Book of foo ",
  7. Description: "bestselling book of Foo by A. N. Other ",
  8. Imageurl: "/images/books/12345.gif ",
  9. Price: "$10.00 ",
  10. Qty: 1
  11. },
  12. {
  13. Title: "javascript pocket reference ",
  14. Description: "Handy pocket-sized reference for the Javascript language ",
  15. Imageurl: "/images/books/56789.gif ",
  16. Price: "$5.50 ",
  17. Qty: 1
  18. }
  19. ]
  20. }

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/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.