The code that is setting behind the click of a button gets executed. In your case, it could be a form submit which means that all the data that the user has inputted is sent to the server which is serving your jsp page.
I would recommend you reading through the Head First
Servlets & JSP book.