Creating a cascading dropdown list box using Java servlets, JavaScript, JSP, a database, and Ajax, all without relying on Jquery or Json

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>

Answer №1

The problem arose due to the specific implementation of my project. I customized the URL structure according to my project requirements, and now everything is functioning properly. The code provided in my question is now executing without any issues.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Alert-Enabled Random Number Generation Tool

I'm struggling to create a program that randomly generates a number between 1 and 20. If the number is less than 10, it should display "fail," and if it's greater than 10, it should display "success." I can't seem to figure out where I went ...

Android App Facing Runtime Exception Crashes

I recently started learning Android development, and I might have made a mistake while creating the interface. Instead of using XML, I coded the interface in Java. However, every time I launch the application on the emulator, it crashes. Here is the stack ...

Are assertations present in both JAVA programming language and JUnit testing framework?

Recently, I came across a question that was posted quite some time ago by an individual named x. For example: assertEquals(driver.getPageSource().contains("sometext"), true); Or: assertEquals(boolean1, boolean2); If the above method exists, I would love ...

Utilize the child array to retrieve the total number in the table

Dealing with JSON data, my task is to count the number of strings within a specific child element and then group them by part of the string to create a table. While this may seem like a confusing and daunting challenge, it's what we need to accomplish ...

Wait until a svelte store value is set to true before fetching data (TypeScript)

I have implemented a pop-up prompt that requests the user's year group. Since I have databases for each year group, I need to trigger a function once the value of userInfo changes to true. My JavaScript skills are limited, and my experience has been ...

Focus on programmatically generated elements by utilizing refs

I need to set focus on the Input within a custom component by creating dynamic refs. This is how I'm currently rendering the elements: const createRefForCountRow = denom => { this[`${denom.id}-ref`] = React.createRef(); return ( <Count ...

Need to verify the heap size currently allocated to tomcat

Using Ubuntu, I want to verify that the heap size setting is being utilized by Tomcat. What would be the best way to accomplish this task? I attempted to use jmap but it appears to be missing from the server. Is there a way to download it individually? ...

Trouble with displaying PHP and AJAX call after switching from JS fetch

Initially, I had a JavaScript function set up to retrieve Wikipedia articles for the chosen country. The code was originally sourced from JS Fiddle and it worked flawlessly. However, I have now been informed that my course mandates all API calls to be made ...

How can I use jQuery to switch classes or activate a click event on the most recently clicked element?

Within my <ul></ul>, there are 4 <li> elements. <ul class="wcarchive-terms-list"> <li class="wcarchive-term wcarchive-term-parent woof_term_224"> <label class="wcarchive-term-label"> <span cla ...

When attempting to render 2 components based on the results of 2 fetch calls using Promise.allSettled(), I encounter difficulties if one of them throws an error

I have encountered an issue while using Promise.allSettled() in sending two fetch calls. I am rendering components based on the result - a component with data if it is fulfilled and an error component if rejected. However, when one of the fetch calls throw ...

Experiencing a compilation error when utilizing the ajaxbehavior event in a listener method within a bean class

When I implemented the ajax listener attribute in my xhtml page, I encountered a compilation error while using the ajax behaviourevent in the listener method of my bean class. The code snippet causing the error is: public void listener(AjaxBehaviorEven ...

"Consistent Behavior: jQuery ajax always triggers fail event, even when success is expected

My web page relies heavily on AJAX requests. Take a look at the following code snippet: function fetchSpecificData(start,end){ var link = createLink('open', start, end); getAjaxResponse(link).done(function(data) { //store data in ...

incrementing the value of an element in a JavaScript array

I'm having an issue with adding numbers to an array in JavaScript. I only want to add numbers that are multiples of three. Below is the code snippet: var numbers = []; for (i = 1; i <= 200; i++) { if i % 3 === 0 { numbers.push(i); ...

What is the most effective way to retrieve the inner HTML of an HTML tag using JavaScript or jQuery?

Let's consider the following code snippet: <p class="question"> this is my paragraph <p> And i'm inside tag in question class <h1> And this is my heading</h1> </p> </p> Now, the challenge is t ...

Organizing nested files with JAWR: a systematic approach

Recently, I started using JAWR to bundle my AngularJS files. However, I encountered an issue where the files were being loaded out of order. Here is my directory structure: app app.js folderA something.controller.js something.module.js I want the f ...

Using TypeScript to send state through history.push({...})

I recently utilized the history.push method to redirect to a specific URL while passing along some information through the included state. Here's how I implemented it: const history = useHistory() history.push({ pathname: '/someurl/', ...

What is the best method for converting a list tag into an array of objects with XPath?

I am attempting to extract the ordered list and generate an array of list tags along with their content. I have experimented with different paths, such as: //li[div/@class="business-info"] //li[div[@class="business-info"]] //li[descendant::div[@class="bu ...

Exploring the getJSON function within jQuery

{ "Emily":{ "Math":"87", "Science":"91", "Email":"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1d6f7e767c51767b727e737f764f747879">[email protected]</a>", "City":"Chicago" }, "Sa ...

Is there a way to use AJAX in Drupal to deliver small chunks of content?

When creating Drupal server pages with themes, the process is typically straightforward. But what if you need it to serve smaller pieces of data, such as JSON? I am interested in having certain parts of my page load asynchronously, like a block that updat ...

Guide to refreshing the modal component with updated properties

In my application, I have created a modal component for managing recipes. This modal allows users to save recipes to a list. let modal = <Modal saveRecipe={this.saveRecipe} closeModal={this.toggleModal}/> However, I also want to utilize the same m ...