How to send form data to Spring controller using ajax / How to Submit Form using ajax

There are scenarios where you want to silently post a form to server or submit a form without a page refresh. Typical example is a Facebook page where you comment on a post. When you comment, the page is not refreshed but the comment is saved somewhere on the server which means that a save request is sent without entire page submit.
This involves the use of ajax. As soon as we decide to use ajax, a question arises as to how we would send form data from jsp to server without page submit and there would be a big hassle involved in form data transmission. Well!!! After reading this post, you won’t feel the same. (more…)

Continue Reading

How to send form fields from jsp to server in Spring MVC / How to submit a form to Spring Controller

Suppose we have a jsp page which has a form whose data should be sent to the server. The form has fields which are directly related to the fields of an entity on the server. An entity is a simple java class which has some fields and their getter and setter methods.
Let’s say the entity is a User (which means we have a User class on the server and each field of the jsp form is linked to a field of User class. When we say linked, it simply means that the name attribute of the form element is the same as the name of the corresponding entity field. (more…)

Continue Reading

How to perform custom initialization of beans in Spring / How to call a method before bean creation in Spring / Callback methods in Spring Beans

There are scenarios where we want to take some actions before a bean is fully constructed and put into service such as

  • giving a specific name to the bean other than that given in the configuration,
  • setting the application context into a bean property,
  • making a log entry immediately after bean initialization etc.
  • (more…)

Continue Reading

How to iterate over a list of objects in jsp / How to create a table from a list of objects in jsp / How to iterate over a collection using jstl

Scenario

Suppose we want to show a list of registered users of the application in a tabular format on a jsp. The list of users is created on the server and is bound to an attribute (in request, session or application scope) if you are using servlet or bound to an attribute in ModelAndView if you are using Spring controller as below. (more…)

Continue Reading
Close Menu