user3331920
user3331920

Reputation: 41

How to add JSP form data into a JSON object and store it in a database?

I have a user entry form with the following fields :

I want to convert its value to JSON and save it in a database. How can I achieve this? Which library can I use ?

Upvotes: 0

Views: 2053

Answers (3)

Nithin CV
Nithin CV

Reputation: 1136

At server side in servlet save all request parameters to corresponding bean and then you can convert using google's gson library for more info check this tutorial

Upvotes: 1

Touchstone
Touchstone

Reputation: 5972

Refer the following steps:

  1. In JSP page, at javascript convert the form fields to JSON using JSON.stringify() method.
  2. At server parse the JSON using appropriate JSON parsers like GSON or Jackson.
  3. After parsing you will get desired object.
  4. Perform database operation on the object.

You will probably need GSON jar , Jackson jar.

Upvotes: 0

Leos Literak
Leos Literak

Reputation: 9474

For example:

  1. You need servlet that takes form submission
  2. To work with JSON I recommend eclipse source minimal JSON, I like it
  3. database - plain JDBC, hibernate or JPA ..

Upvotes: 0

Related Questions