Servlet is having trouble retrieving the latest value from the XML file

We have a Java Web Project where we utilize a Servlet to update a specific XML tag value. The updated value is obtained from a webpage and passed to the Servlet. However, when the Servlet tries to fetch this updated value from the XML for further processing, it retrieves the old value instead of the updated one.

public void setPeriodID(String bookingsBOPeriodID) throws InterruptedException {

                            try{
                                            final String FilePath=UtilLib.getEnvVar("ConfigXMLFilePath");
                            String filepath = FilePath;
                            String bwperiodid=" and ";
                            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
                            DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
                            Document doc = docBuilder.parse(filepath);

                            // Get the staff element by tag name directly
                            Node Parameters = doc.getElementsByTagName("Parameters").item(0);
                            // loop the staff child node
                                                            NodeList list = Parameters.getChildNodes();
                                                            for (int i = 0; i < list.getLength(); i++) {    
                                               Node node = list.item(i);
                            //BookingsBO
                            if (bookingsBOPeriodID!=null && bookingsBOPeriodID.length()!=0 && "BookingsBOINPeriodId".equals(node.getNodeName()) && bookingsBOPeriodID.indexOf(bwperiodid)==-1  ){
                                            System.out.println("***** Updating Bookings BO IN Period id ********");
                                            System.out.println("inside updateEnvPeriodID::"+bookingsBOPeriodID);
                                            node.setTextContent(bookingsBOPeriodID);
                                            // node.setNodeValue(bookingsBOPeriodID);  
                             } 
               }
                                                            // write the content into xml file
                                                            TransformerFactory transformerFactory = TransformerFactory.newInstance();
                                                            Transformer transformer = transformerFactory.newTransformer();
                                                            DOMSource source = new DOMSource(doc);
                                                            StreamResult result = new StreamResult(new File(filepath));
                                                            transformer.transform(source, result);
                                                            System.out.println("******* Period Id details updated **************");                          
                            } catch (ParserConfigurationException pce) {
                                pce.printStackTrace();
                            } catch (TransformerException tfe) {
                                tfe.printStackTrace();
                            } catch (IOException ioe) {
                                ioe.printStackTrace();
                            } catch (SAXException sae) {
                                sae.printStackTrace();
                            }
                            System.out.println("in period id after update :"+ UtilLib.getParam("BookingsBOINPeriodId"));
}

The value passed from the web interface is stored in the variable "bookingsBOPeriodID". Despite being passed correctly, the new value does not reflect immediately in the XML after executing this method.

Answer №1

Delay your code execution before retrieving information from the xml file. Ensure that your resources and processes are synchronized for these tasks.

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

What could be causing a parse error and missing authorization token in an AJAX request?

I recently wrote some code to connect a chat bot to Viber using the REST API. The main part of the code looks like this -: $.ajax({ url : url , dataType : "jsonp", type : 'POST', jsonpCallback: 'fn', headers: { 'X-Viber-Auth- ...

Tips for invoking a particular function when a row in a Kendo grid is clicked

I have a Kendo grid named "mysubmissionsGrid" and I want to execute a function when each row is clicked with a single or double click. How can I accomplish this? <div class="col-xs-12 col-nopadding-left col-nopadding-right" style="padding ...

Manage the timing of ARI function calls by utilizing the power of JQuery and socket.io

Currently, I am facing a challenge where two functions are automatically called when adding a call to a bridge. I aim to use JQuery to ensure these functions are only triggered upon button click, and then proceed with server-side modifications. The issue ...

Unable to receive parameters in Java Servlet POST request action

Recently, I decided to delve into the world of Tomcat and Servlets, coming from a background in IIS, C#, and MVC. To enhance my project, I am also incorporating AngularJS and Guice. I have created a Servlet with a single method: @Singleton @SuppressWarn ...

Encountering the "TypeError: Unable to access property 'indexOf' of undefined" error while utilizing the ipfs-api

During my development work with the ipfs-api, I ran into an issue where adding an image file to the ipfs node was not functioning properly. Upon further investigation into the error details, it appears that the protocol is being treated as undefined in the ...

The button vanishes once the score is shown

Having trouble creating a simple incremental "clicker" game where the button disappears and the score increases every time it's clicked index.html <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.1 ...

Am I going too deep with nesting in JavaScript's Async/Await?

In the process of building my React App (although the specific technology is not crucial to this discussion), I have encountered a situation involving three asynchronous functions, which I will refer to as func1, func2, and func3. Here is a general outline ...

Restrict the number of GET requests made using D3.js and the Twitter API

Currently, I have made adjustments to my D3.js chart by switching from mouseover/mouseout events to mousemove. While this change has caused several issues in the chart, the most significant one pertains to my GET statuses/show/:id requests. In the past, h ...

Error message in React-router: Cannot read property 'func' of undefined, resulting in an Uncaught TypeError

When attempting to launch my react application, I encountered an error in the browser console: Uncaught TypeError: Cannot read property 'func' of undefined at Object../node_modules/react-router/lib/InternalPropTypes.js (InternalPropTypes.js: ...

Sending images as a base64 string from a Titanium app to a Ruby on Rails web service

I am encountering an issue when trying to upload an image from an app that has been converted into a base64 string to a Ruby on Rails server. The app is developed using Titanium. However, after retrieving and decoding the image string back into an image, ...

What could be causing my two-dimensional array to display only zeros?

I am facing an issue with my 2-D array called Maze, which is a global variable in my code. I have hard-coded the data at each position using my setData() method. However, when attempting to print the array below, it only prints zeros. Can anyone help me ...

The failure to initialize lazily in Hibernate/Spring may occur due to the absence of a session or if the session

Looking for an answer? Scroll to the end... The issue at hand has been raised multiple times. I have a basic program featuring two POJOs: Event and User, where a user can have multiple events. @Entity @Table public class Event { private Long id; privat ...

Updating an HTML value based on the selected option using JavaScript

I'm working on a form that included a select element: <select class="form-control"> <option>10 pc</option><!--1 USD --> <option>20 pc</option><!--2 USD --> <option>50 pc</option><!--3 USD ...

Securing MongoDB Data with Java Spring Framework

Currently, I have a Spring application built with Java 11 and I am exploring more secure ways to encrypt the data stored in MongoDB. Right now, I have a method for encrypting user passwords: @Bean public PasswordEncoder encoder() { return new BCryptPa ...

Angular 2 Error: Unresolved Promise rejection - Unable to assign value to reference or variable

I'm currently working on an Ionic 2 app that includes a barcode reader feature. However, I encountered the following issue while trying to display data: Unhandled Promise rejection: Cannot assign to a reference or variable! ; Zone: ; Task: Promi ...

Analyze the input number against a specific value stored in an array

I created a software application to manage a dog kennel. It allows users to add a new dog, list all dogs with a tail length equal to or greater than a specified length, remove a dog from the kennel, or stop the program altogether. The issue arises when att ...

Leveraging the AngularJS promise/defer feature alongside the Quickblox framework, learn how to efficiently upload images and subsequently upload public URLs to a custom

I am currently developing an application that requires users to upload 5 images of themselves. Using a backend-as-a-service platform like Quickblox, I have to create and upload blob files individually. Once each image is uploaded, I receive a success call ...

Guide to integrating selenium webdriver into a Java Applet

After attempting to automate tasks using Selenium with Python, I've found that Java seems to be the more effective choice. My goal is to automate form filling and submission using Selenium, with the form containing 10 fields. While I have successfully ...

Is it possible to utilize an Angular2 service with the DOM addEventListener?

Issue: I am encountering an problem where the service appears to be empty when trying to call it within an addEventListener. Html: <div id="_file0"> Service: @Injectable() export class FilesService { constructor(private http : Http) { } } Co ...

Selenium unit test triggers Firefox to crash

I recently started using Selenium.WebDriver (v2.45) for running visual tests. For my web driver, I opted for FirefoxDriver. I made sure to install Firefox 38 as required. However, when I tried running a test, Firefox threw an exception with the following ...