0

I have been developing using java swing but I need to change to Java web. Normally I would write a itemStateChanged method like this:

public void itemStateChanged(ItemEvent eie) {
        Object obj = eie.getSource();
        if (obj == cboDormitory) {
            //My other Actions here
        }
    }

This way I am able to populate other JcomboBoxes with data from the database based on the selection of the first JComboBox. I need to find a way to do the same on a jsp page. I would really Appreciate an example. Thank you in advance.

Stanley Mungai
  • 4,044
  • 30
  • 100
  • 168

1 Answers1

1

The model is completely different here because the code is running in two places now. Unlike the desktop app where the user selects a value from the combo box in the app and the same app responds, now you have the user selecting a value in their browser and the browser sending a request to the server and the server sending a response back, and the browser interpreting that response.

You need to read up on AJAX. (You could start here: How to use Servlets and Ajax? ) Basically, it will work like this:

  1. You will use Javascript to catch the events on the client side and send an AJAX request to the server. You will also use Javascript to parse/handle whatever response is returned from the server.

  2. You will use JSP or a Servlet to receive the request and return something. Based on your example, let's say a new set of values for combo2.

Community
  • 1
  • 1
developerwjk
  • 8,619
  • 2
  • 17
  • 33