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 override hashcode() and equals() method in java

hashcode() and equals() : Overview

hashcode() and equals() methods are defined in java.lang.Object class which is the super class of all classes in java and hence may be overridden in any class.

    • The signature of hashcode() method is public int hashCode() which means it should return an integer, and
    • The signature of equals() method looks like public boolean equals(Object obj) which means it returns a boolean value indicating whether the object which called it is equal to the object which is passed as an argument to it or not.

(more…)

Continue Reading

How to calculate next working day in java / How to increment date excluding weekend in java

It may happen that you need to add some days to a particular date and the resultant date is falling on either Saturday or Sunday. So you have to calculate the next working date.

Practical Application : This is usually required in payments industry where the dates are written to files and these files are then uploaded to server but the server rejects the file if the date is a holiday. In such cases the date should be checked to be a holiday before writing it to file and incremented to a working day and then written to the file so that it is not rejected. (more…)

Continue Reading

How to perform operations on select box using jQuery / Drop down jQuery cheat sheet

There are many operations which we have to perform on select boxes (or drop downs) such as selecting an option based on index, selecting an option based on visible text, removing an option etc. using jQuery.

Most of the times, we do not remember the selectors or methods to accomplish the required task and we end up searching the Internet giving away our valuable time. In this post, I have tried to accumulate various operations and their methods which should be helpful to many. Read On !!! (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

How to send data from one JSP page to another

A web application developed using Java EE would definitely be using JSPs and would indeed involve transferring values from one JSP to another.
For Example, a user is presented with a form where he fills the required details and presses a Next button where all those details are pre-filled in a non-editable form for him to confirm. The user checks the details to be correct and submits the form for further processing.
The above scenario is pretty common and involves taking data from one JSP to another. This post addresses the approaches to achieve that. (more…)

Continue Reading
Close Menu