繁体   English   中英

Servlet 无法从 XML 获取更新的值

[英]Servlet Unable to Fetch the updated value from XML

在 Java Web 项目中,我们使用 Servlet 使用来自网页的值更新 XML 标记值,然后为了进一步执行,Servlet 必须从 XML 获取更新的标记值并继续,但它正在检索旧值(在更新之前)并继续。

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"));
}

来自 webinterface 的新值通过 "bookingsBOPeriodID" 传递。 在此方法之后,新值未立即反映在 XML 中

在从 xml 读取数据之前,让您的代码等待一段时间。 您应该为此类操作同步您的资源和进程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM