PHP variables to Java applet? - java

I have an audio visualizer applet I created with processing and minim using fft to analyze the audio. Now I want to feed in songs to the program dynamically with php as the user clicks on a song. I have read about JavaBridge and have it up and running with Tomcat. Would I need to store the song variable values in an xml file and send it over to the .java file? Is that the right approach? And if so, any idea what this would look like? I'm completely new to java and processing. Any help would be incredibly appreciated!

feed in songs to the program dynamically with php as the user clicks on a song.
Translations presumed for answer:
PHP to HTML.
'clicks on a song' to 'clicks on a link'.
Since the HTML has links to songs, add an onclick() handler and in the called function, use JavaScript to call an applet method to load the required song.
So long as the applet is loading the song from the code base or document base, this should be allowable in a sand-boxed applet. Unfortunately doing so from a method called from JS complicates matters slightly, since the security sand-box is tightened even further.
If that is the case here, it will be necessary to wrap the call in a PrivilegedAction and call it using AccessController.doPrivileged(PrivilegedAction)

The fundamental sequence is as follows:
The user request a .php page in the browser.
The web server lets PHP write the page.
It can write HTML with an applet specified, the applet HTML can be written with parameter with values filled in by PHP.
The client receives an HTML page, which starts the applet.
So a click on the page cannot be handled by PHP, in a simple direct way. Follow #AndrewThompson in this.

Related

(Java) Is it possible to read Internet Explorer form data?

I'm just getting started with this process, but figured I'd ask if it is possible with only Java.
At work, we use an intranet for much of our work. I am developing an application that uses some of the information from those websites. However, we currently need to copy from IE and paste into my JavaFX application.
I was wondering if Java provides any sort of integration with the Windows API that would allow me to automatically pull that data from IE to my app.
For example, there is a web-based form with several textfields; I want to be able to capture the text that is written in them, programatically.
EDIT: I do not have access to the website code directly.
mmm i dont think it work that way,
you can make a java scraper , who is a program to get the code html of a certain page, but you cant get data from a form, because the clients are diferents.
maybe you can send from web client form the user/password to an app, but you cant make an intrusion from app to a form who is in a web page with content in the value of form fields
So you need to get form data from IE but you can't put code into the website. It sounds like a task for a plugin. Consider developing your own plugin or extension (probably in javascript) in IE.

Accessing the same file

I have a situation where in I write to a text file programmatically using java and simultaneously I read from the same file using jQuery.
The problem I face is jQuery is unable to find the updated content whenever a content is written into the text file via java.
I have Googled a lot but the only results I find are for java and java processing and not for java and javascript (i.e A Client side and Server side)
I am not sure if this is even possible.
More about the question:
I write into the file the crawling results using java and I am trying to display the same using javascript (jQuery.post() method).
JAVA
A multi-threaded crawling program that crawls a website and does some functionality. I am trying to write some content into a text file using the same java program as and when the crawling happens. The content I write mostly are the details about which thread is getting invoked and what is the current link that is being crawled.
The reason I write this in the text file is I need to show the output in the UI so that people looking at the UI will understand what happens.
Writing happens perfectly as expected.
JAVASCRIPT (jQUERY)
This using the
jQuery.get or post ("sample.txt", function (result) {
$("#someID").html(result);
});
It reads from the text file normally but when java and javascript both are trying to access the file, It is the java that dominates leaving javascript behind thus jQuery is unable to fetch the updated content as and when it happens.
I guess this explanation is more than sufficient to make people understand what exactly my problem is !
On the whole, java and javascript try to access the same file at the same time. So there comes this issue.
Any help is appreciated.
Thanks in advance
I think the file is cached. Easiest thing is to request the file by different urls. Try something like "sample.txt?rnd="+Math.rand()
There can be synchronization problems and your data will be corrupted.
I have a question, is it must be done with Ajax? I think you are trying to figure out about
Ajax push and pull
This is not very easy to do and I wouldn't really recommend it. However, there is a better technology called websocket. So what you can do is, client can submit request to the server to write data into a file then server can send back updated content to the client. Moreover, this is much better than achieving the same objective through numerous amount of HTTP requests.
Additionally, if you want the crossbrowser compatibility, have a look at http://socket.io/
Thanks for all those who were trying to help me out.
I have finally come up with a solution. I, instead of using jquery post to directly read from file, am using another jsp file that reads the file contents and prints using out.println on screen, and after which I am using jQuery post to get the content written by that jsp file. Hence the synchronization problem is avoided.
Here is more about my explanation:
Earlier I had
java program -> Text File <- javascript (jQuery post) // Resulted in synchronization problem where in javascript was not able to access the updated content.
Now
java program -> Text file <- JSP file <- javascript (jQuery post) // Avoided the synchronization problem as that file is accessed by the same server side language. After that jQuery reads the content printed by JSP page.
After many changes, finally came up with one good working solution.
Thanks all.

How ajax file uploads work?

We know that, JQuery ( or javascript ) can not access local file system. So how does the various ajax file upload plugins of jquery actually work and even show the progress bar ?
I once made an File Uploader using Java Applet and I could do it because somehow I was able to read the file from the local file system using applet. Because I was able to read it, I sent it a 100 lines at a time using ajax.post in multiple parts of 100 lines and as each of the part is successfully sent, manipulated the progress bar accordingly.
But, when we can not read the file from file system, then how do the ajax plugins of jquery show the progress bar and upload the files asynchronously ?
Typically, there is a handler on the server side accepting the post, and then another handler to report progress of any upload.
If you give an example framework to use, we can give a more specific answer.
They all have some sort of back end component that runs on asp/.net or .php (there are others, of course)
There is no way to implement an uploader on your site without something on the back end to save the files.
They use flash. See: http://www.uploadify.com/
Some, now use HTML5 features.
Not necessary that it will use flash . I have custom uploader where I am showing progress in a div with filling it by color based on process done . I have a uploadtracker.js which returns progress done and based on that I saw that div process based on its return value.
Check these samples .
http://malsup.com/jquery/form/#file-upload
Here are some other in case any of them helps .
http://www.tutorialchip.com/jquery/9-powerful-jquery-file-upload-plugins/

where to save a jpeg file from an applet

I have a java applet that creates a JPEG file. I want to pass that file to a Javascript where it can display and print it. The only way I can think of doing this is to save the jpeg to a temporary storage area on the user's computer and then pass the path of the file to the javascript which picks it up and displays it. This raises a two questions:
Where should the applet store the file. If you suggest the temporary internet files folder, then how do I find that path to that folder?
Is there a better way to do this? Can I pass the JPEG directly from java to javascript without first writing out to a disk?
Thank you in advance for your help.
To store file on users's machine your applete should be signed, and user should give necessary permissions to your applet (through special dialog window which is shown automatically).
Read this article about modifying DOM from applet
Another approach is to save your image on the server (pass it from your applet to the server) and then reload page (or use Ajax, but in this case you probably have to make ajax calls every few seconds to check if the image is available on the server).
Can't you just have an applet that displays the picture and prints it?
I don't think it'd be possible to do this in IE before IE8 (and it's wimpy even in IE8), but in other browsers your applet could make the image data available to Javascript (please don't say, "a Javascript"; it's like saying, "a FORTRAN" or "a Java") and then from Javascript you could create an <img> tag with a "data URI". See this reference: http://en.wikipedia.org/wiki/Data_URI_scheme

include a cpp file in jsp

i am very new to jsp... i am currently doing a project where i have to interface a card reader with my html page.
i got the card-reader code in a cpp and .h file. is there any way i can use these file with my jsp.. or do i have to recode it in java and include a .js file.
specifically, i have a text input for ID on my page. i need it to be populated with the input from card. i got the code to interact with card and extract that number in cpp program. so can i like call that function from my html page?
Why on earth you need to interface your card-reader to your JSP page. It doesn't make any sense to me, I am sorry. First understand that JSP is a Java web technology for presentation, which runs on server and spit HTML to the browser. Hence, what you get on the client is HTML.
Now, could you please elaborate what you are trying to achieve?
There are several way to do this:
You could do a system call from your jsp if your C++-code can run standalone.
You could use a Java-C++-bridge.
You could use the Java Native Interface.
You will have to look into the Java Native Interface if you want to reference C++ code from java.
For more information see the following:
Wikipedia
API Guide
Nice Guide in PDF format
A jsp renders HTML, in the part you will see in your browser you are no longer in your jsp, you are not even in your code anymore.
If you want to read a card from an HTML page you will need to ignore the fact you have jsp technology and realise its HTML technology you are using.
SO you will need an applet, some flash, some activeX or other browser technonlogy first before even trying to interface with the cpp
if you need to read from card JSP cannot help you. If you read card number otherwise and send it to JSP with POST, then you do not need any reading. What you might need is signed applet on user's side which will try to read card from card reader. Then I will advise you to use javax.card - java 1.6 has a support for reading smart cards ...
http://java.sun.com/javacard/

Categories