I am working on java web application. In my application some user defined javascript using.
When i update my javascript file and run my project in browsers, so first time not get updated javascript file and when i refresh (ctrl+F5) page after get updated javascript file.
so why first time i don't get updated javascript file?
Please guide me.
You need to adjust the cache headers that your server is sending. Specifically, you need to lower the expiration date that clients are likely to use for things like Javascript files.
Otherwise, the client is going to cache them -- just like they are supposed to do.
Related
im starting to get on web development and I can use some help with this issue:
Im trying to do a web table where I can follow changes in market values.To do this im using a java API created by the company that provides me with the data; this API connects through sockets to a gateway server on my company that receives this info directly from their market databases.
The java app receives the data in real time and every 5 minutes creates an .txt document on the server. This .txt document is then read by the html page using a JS script I found.
I now this is a really crappy way to update the table and I want know if its possible to get the data in realtime directly to the page using JSP.
Thanks for your time.
In my opinion the cleanest implementation would be:
Database that holds the values you wan't to show.
Scrip / procedure that calls the API and stores the values in your database
Your page reads the values from the your database.
I wouldn't go for a real time solution, because then you have to wait for the API call evertime your web page is loaded.
On the other hand, it's possible to parse an external webpage / api with php, and include it directly in your page. Without the database in between.
But again - Then you'll notice a slower responce, and make an unnecessary API call evertime your page is reloaded.
XML parsing with PHP: http://www.php.net/manual/en/book.xml.php
I am trying to trigger an event in JavaScript using a Java class.
How can I send javascript code (either direct input or from a file) in a Java class to a specified destination file which is already opened in the browser (Firefox)?
Currently I'm using the ScriptEngineManager to run my JavaScript code, but the code is executed in my Java environment and I don't know how to trigger an event in this way (as I cannot use e.g. window.postMessage("hi", "*");)
Any suggestions how to solve this? Work-arounds are also appreciated (preferably without extensions, plugins, ...).
Best regards.
When executing from java you have no access to window events - because there is no browser.
I don't really understand the use case here but you could load the destination file into an iframe and then do a meta refresh - once you update the files contents then the updated results will be displayed on the next refesh.
In any case you can only return results from the inputted javascript functions back to java - not call events.
You could pass a javascript function (a call that simulates the event) back to the browser and then execute it.
How you would pass this back to the client depends on the situation :
It could be on the response of the request to upload the javascript
You could use the meta-refresh mechanism
You could look into an ajax style way with client polling (if you didn't want to refresh manually each time).
EDIT
The server has no link to the browser between requests. To asynchronously receive a server event in a browser you could have a look at:
WebSockets
Comet
So the browser would receive notification when the task is complete and then it would be able to react - for instance prompt for the tab to close.
I don't if the question title fits, but here is my problem:
I have a regular webhosting service in hostmonster, with a website built in php.
So I have php script running in a cron job that monitors a xml file for changes, and everytime a new entry comes into that xml file the script stores it in a database.
In the other hand there is java built desktop client, which needs to be noticed ASAP that a new entry is created, for this the client connects to a second php file every second, and this second files tells if there has been changes or not.
The thing is, every 260 connections my I.P gets banned from the server :( and the client crashes, the client will be used by several users.
I contacted support on how to handle this, but they tell me to use a single connection, I tried reusing the UrlConnection but after the first request it just gives null. then I tried with Sockets but no luck. I know there are libraries that manage this but I dont know how are they called. Can someone give me advice?
thank you guys.
Use a long polling method. Hold the connection opened until response arrives. This way you only need to ask for the update once.
PHP may not be the best tool for this job though.
I am preparing a program in java and its purpose is to make the HttpWebRequest for a url which can open in any browser (i am planning to use watij for opening the page in different browser).Now my program should take the screen shot of the presently opened url once the page has loaded successfully.I need to run a piece of code after the browser has loaded successfully in the browser.I dont want to use the javascript document.ready function for identifying if the page is loaded successfully or not.I should be able to know the page load complete status in the server side (s0 that i can execute that piece of code for taking the screenshot).How can i do it in java.Or is there any other way to do achieve that if its not possible in java.May be create some plugins.
An early reply is highly valued,
Regards,Sagar.
you can do it using applet, [just taking snapshot i meant that you want.]
In a server-side application running on Tomcat, I am generating full HTML pages (with header) based on random user-requested sites pulled down from the Internet. The client-side application uses asynchronous callbacks for requesting processing of a particular web page. Since processing can take a while, I want to inform the user about progress via polling, hence the callbacks.
On server-side, after the web page is retrieved, it is processed and an "enhanced" version is created. Then this version has to go back to the user.
Displaying the page as part of the page of the client-side application is not an option.
Currently, the server generates a temporary file and sends back a link to it. This is clearly suboptimal.
The next best solution I can come up with inolves creating a caching-DB that stores the HTML content together with its md5-sums or sha1-ids and then sends back a link to a servlet, with the hash-ID as an argument. The servlet then requests the site from the caching-DB.
Is there any better solution? If not, which DB-backend would you propose? I'm thinking of SQLite. Part of the problem to be solved is: how do I push a page <html> to </html> back to client side?
If true persistence isn't required how about using something more temporal like memcached instead of SQL? Calling semantics are pretty clean and easy - and of course you can expire the data manually, ttl, or # restart.
Instead of creating a temporary file, filling it up, and then sending a link, you can create a memory buffer, fill it up, and then send that as the response (serve it with mime-type 'text/html'). If you don't want to send page-buffers immediately, you can save them for later in the user's session. If you're worried of taking up too much memory that way, you may want to keep only a certain number of page-buffers around in memory, and write the rest to disk for later retrieval. Using a DB sounds like overkill (after all, there's no relational information involved) - but it would solve the caching problem nicely.