You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by fireportal <fi...@hotmail.com> on 2009/11/10 09:44:08 UTC

tomcat caching

Hi, i have this problem of i am able to edit the xml file but when i try to
link it up with a piechart using amchart, the data shown is that of the
previous data before the update. It is only when i open up the xml file to
refresh it that it is able to show the new data.
Tried setting cachingAllowed to false and reloadable to true but the problem
still exisit. Tried to add a parameter to the output file like this String
outputFile = "../Googlipse/twitter.mining/WebContent/Pie.xml?" + new Date(); 
but there is error.
Please help. Thanks a lot!! Really desperate

My code is as below

String inputFile = "../Googlipse/twitter.mining/WebContent/Pie.xml";
	 String outputFile = "../Googlipse/twitter.mining/WebContent/Pie.xml";
			
			Document doc =
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new
InputSource(inputFile));
				XPath xpath = XPathFactory.newInstance().newXPath();
	    		NodeList nodes =
(NodeList)xpath.evaluate("//slice[@title='Positive']", doc,
XPathConstants.NODESET);
	     
	    	
	    		for (int idx = 0; idx < nodes.getLength(); idx++) {
	    			nodes.item(idx).setTextContent("6");
	    		}
	     
	    		
	    		Transformer xformer =
TransformerFactory.newInstance().newTransformer();
	    		xformer.transform(new DOMSource(doc), new StreamResult(new
File(outputFile))); 
	    		

Retrieving the xml file:

	<script type="text/javascript">
		// <![CDATA[	
	
		var so = new SWFObject("ampie.swf", "ampie", "360", "300", "8",
"#FFFFFF");
		
		so.addVariable("settings_file",
encodeURIComponent("ampie_settings1.xml"));
		so.addVariable("data_file", encodeURIComponent("Pie.xml"));
		so.write("flashcontent");
		// ]]>
	</script>
-- 
View this message in context: http://old.nabble.com/tomcat-caching-tp26280018p26280018.html
Sent from the Tomcat - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: tomcat caching

Posted by Pid <pi...@pidster.com>.
On 10/11/2009 08:44, fireportal wrote:
>
> Hi, i have this problem of i am able to edit the xml file but when i try to
> link it up with a piechart using amchart, the data shown is that of the
> previous data before the update. It is only when i open up the xml file to
> refresh it that it is able to show the new data.

You are referring to "the xml file" as if it's something we all know about.

> Tried setting cachingAllowed to false and reloadable to true but the problem
> still exisit.

The reloadable attribute doesn't do what you think it does.  Read the 
docs for your Tomcat level again.

> Tried to add a parameter to the output file like this String
> outputFile = "../Googlipse/twitter.mining/WebContent/Pie.xml?" + new Date();
> but there is error.

There's an error because you can't append a query string to an output 
file path.  Query strings are added when you perform a request for a 
path or file, but not when writing inside the file system.

Even if you could make it work, you'd then have a file called:

  fail.txt?x=2

which you couldn't add a query string to when requested in a browser.

  fail.txt?x=2?q=bah


> Please help. Thanks a lot!! Really desperate

It would help if you explained yourself properly, rather than jumping in 
and assuming someone happens to suffer from Internet Telepathy.


> My code is as below
>
> String inputFile = "../Googlipse/twitter.mining/WebContent/Pie.xml";
> 	 String outputFile = "../Googlipse/twitter.mining/WebContent/Pie.xml";

These are relative paths.

Obviously I can't tell what they're relative to, because I have no idea 
whether this code is running on an Android phone or in a class deployed 
in a Servlet Container.  (Hint: more info required).

I can't tell even if you're updating the right file*.

> 			Document doc =
> DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new
> InputSource(inputFile));

This might work, but I can't tell because I don't know where it's 
measuring the relative inputFile path from.*

> 				XPath xpath = XPathFactory.newInstance().newXPath();
> 	    		NodeList nodes =
> (NodeList)xpath.evaluate("//slice[@title='Positive']", doc,
> XPathConstants.NODESET);
> 	
> 	    		for (int idx = 0; idx<  nodes.getLength(); idx++) {
> 	    			nodes.item(idx).setTextContent("6");
> 	    		}
> 	
> 	    		
> 	    		Transformer xformer =
> TransformerFactory.newInstance().newTransformer();
> 	    		xformer.transform(new DOMSource(doc), new StreamResult(new
> File(outputFile)));

Likewise, the relative path might work, or might not.
So, you attempted to update an XML file of some unknown format. (Hint*).

> Retrieving the xml file:
>
> 	<script type="text/javascript">
> 		//<![CDATA[	
> 	
> 		var so = new SWFObject("ampie.swf", "ampie", "360", "300", "8",
> "#FFFFFF");
> 		
> 		so.addVariable("settings_file",
> encodeURIComponent("ampie_settings1.xml"));
> 		so.addVariable("data_file", encodeURIComponent("Pie.xml"));
> 		so.write("flashcontent");
> 		// ]]>
> 	</script>

I'm not entirely sure what encodeURIComponent() does*, if it doesn't add 
anything to the URL, then it's somewhat pointless.

If you want to add a param to the URL, this is the place to do it, 
assuming encodeURIComponent() doesn't do anything unusual:

  encodeURIComponent("Pie.xml?d="+(new Date()).getTime())


The problem is not Tomcat, the problem is that your browser is caching 
the Flash/XML file.  You need to ensure that the XML file is sent with 
"no-cache" type headers, which you can do with a simple servlet Filter.

If you have not thoroughly read the Tomcat docs, wiki & examples, now 
would be a good time.


p


* Because you didn't tell us.  Start by assuming that we don't know what 
you've spent the last 24 hours doing.

It's also preferable to tell us Tomcat, OS, JVM version when you ask a 
question to avoid people like me sending snippy replies when we have to 
guess what you're trying to do.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org