My experience with Ajax is limited, but I am eager to utilize it to create a cascading drop down list box for my project. While I have found resources online that demonstrate the use of Ajax with JSON and JQuery, I am specifically looking to implement Ajax with JavaScript alone. Below is a brief overview of the issues I am facing and I would greatly appreciate any guidance provided here. Thank you in advance. 1. I need to establish two drop down list boxes. 2. The values for the first drop down list box are hardcoded within the JSP page. 3. Depending on the selection made in the first drop down list box, the values for the second drop down list box should be populated from a database. 4. My goal is to achieve this using JSP, JavaScript, Servlet, and Ajax - not relying on jQuery or JSON. Could someone assist me with example code snippets?
I have attempted to make a request in my JavaScript. I have specified the URL for my servlet, yet the request does not reach the servlet page. I added a system out statement in my servlet's doGet method for testing purposes, but the message did not appear in the console. Please see my code below and provide guidance.
//my JavaScript code
function testDDL{
var xhttp;
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET", "testServlet", true);
xhttp.send();
}
//my servlet code
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
System.out.println("I am in Test Servelet");
}
//my web.xml configuration
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.test.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/testServlet/*</url-pattern>
</servlet-mapping>