user448402
user448402

Reputation: 157

How to return JSON from a servlet based on request parameters

How do I use JSON in java servlet? Using the URL, to pass parameters from a POST servlet, the JSON would respond based on the URL parameters.

Upvotes: 0

Views: 1112

Answers (2)

Pablo Santa Cruz
Pablo Santa Cruz

Reputation: 181280

You need a JSON library in Java. With that library, you will be able to serialize Java Objects into JSON objects, and send them through HttpServletResponse instance in your Servlet.

Upvotes: 2

Andrzej Doyle
Andrzej Doyle

Reputation: 103797

"How do you use it"?

JSON is simply one way of representing hierarchical data (such an an object model) in a flat text format (such as an HTTP body, or filesystem file). So you'd use it to represent hierarchical data in these situations.

If you mean how do you parse/create it, there are many mature libraries for JSON handling.

Perhaps a specific situation or use case would assist in pinning down your question, if the above is not the answer you were looking for.

Upvotes: 0

Related Questions