Javatpoint Logo
Javatpoint Logo

Comment Form Example using AJAX in Java

In this example, we are creating a form to post comment. The form data is saved in the database and a list of all posted comments are shown below the comment form.

Steps to create comment form example using AJAX in Java

You need to follow following steps:

  1. Create table in database
  2. load the org.json.jar file
  3. Create comment form
  4. Create server side page to save the form data and print all posted comments

Create table in database

In this example, we are using oracle 10g database. The table structure is given below:

comment form table

The id field of "usercomment" table is auto incremented.


Load the org.json.jar file

download this example, we have included the org.json.jar file inside the WEB-INF/lib directory.


Create comment form

In this page, we have created a form that gets input from the user. When user clicks on the Post Comment button, postComment() function is called. We have written all the ajax code inside this function.

index.html

Create server side page to process the request

In this jsp page, we are writing the database code to save the comment and print all comments.

index.jsp


Output

See the comment form.

ajax comment form example output 1

Now write comment and email id, then click on the "Post Comment" button. A list of posted comments will be displayed below the comment form.

ajax comment form example output 2




Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA