2016-03-23 13 views
-1

Java Webプロジェクトでは、サーブレットを使用してWebページからの値を使用してXMLタグ値を更新し、さらに実行するためにサーブレットはしかしXMLは、(更新前の)古い値を取り出して処理しています。サーブレット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に反映されません

+0

プロジェクトをきれいにしてサーバーを再起動してください –

+0

@Khan:私たちはそれが助けにもならないことを試みました。このフローは、@ Update XMLのようなもので、操作を実行するための値を取得します。サーバー上で手動で実行するとうまくいきますが、Webインターフェイスから同じものを実行しようとするとそうではありません。 –

+1

コードをuploqdできますか? –

答えて

1

xmlからデータを読み込む前に、コードがいつか待つようにしてください。 このような操作には、リソースとプロセスの同期が必要です。

関連する問題