0

I am developing one sample web application in JSP. In this application i want to call the servlet method after some action triggered, For example the list of department is displayed in the drop down list, after selecting the department i want to retrieve the list of students name from the database. Am new to jsp any one help me to achieve this, Thanks in advance.

<form method="post" action="index.jsp" name="form1" onsubmit="return checkme()">

            <table cellpadding="2">
                <tr>
                    <td>
                        <p style="color: blue;font-family: sans-serif;">Select Project:</p>
                    </td>
                    <td>
                        <select id="project" onchange="">
                          <option value="0">Select..</option> 
                          <c:forEach items="<%=department%>" var="entry">
                                <option value="${entry.key}">${entry.value}</option>
                          </c:forEach>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        <p style="color: blue;font-family: sans-serif;">Select Employee:</p>
                    </td>
                    <td>
                       <select id="employee">
                           <option value="0">Select..</option>  
                           <c:forEach items="<%=emplist%>" var="entry1">
                                <option value="${entry1.key}">${entry1.value}</option>
                           </c:forEach>
                        </select>
                    </td>
                </tr>

            </table> 


            <input type="submit" value="Submit">

      </form>
Krutik Jayswal
  • 3,165
  • 1
  • 15
  • 38
PS Kumar
  • 2,096
  • 6
  • 30
  • 45

3 Answers3

0

An ajax call using jquery will be the cleaner and efficent way of doing it. Something like this:

        $.ajax({
            type : "GET",
            url : "yourservletURLWithParams"
            success : function(data) {
               //update list
            }
        });
Juned Ahsan
  • 67,789
  • 12
  • 98
  • 136
0

As an addition to @JunedAhsan 's answer you can accomplish the same without jquery too:

function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
       //success handler
    }
  }
xmlhttp.open("GET","yourservletURLWithParams",true);
xmlhttp.send();
}
dehlen
  • 7,325
  • 4
  • 43
  • 71
0

Here you will find similar type of question and also answers with detail description and sample code. Populating cascading dropdown lists in JSP/Servlet

Hope this helps!

Community
  • 1
  • 1
Ranjitsinh
  • 1,323
  • 1
  • 11
  • 28