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
Related
I've been trying to do this in a liferay module project. By making an input type=file in my view.jsp and saving it in a java File variable but i can't get it to work. Is this possible? and if yes, how?
So far i've looked for a paramutil method that i can use but there don't seem to be any. And i've tried to use request.getParameter but this doesn't allow for the type File to be used. After that I tried to create a upload request and fill it with the data from the form. But this also didn't work for me.
I wanted to make a form in my jsp file and let people upload a file via the input and let my java code run on submit to add the file to the documentlibrary.
A java File (as in java.io.File) is an abstraction for a pointer to something sitting on your file system. When you upload data in a portlet or any other means in a web application, you're first dealing with a stream of data that usually has no representation on the hard drive (unless you explicitly store it there). Thus, ParamUtil will not reveal anything of type File, because that's - by definition - not part of a http request.
There is a lot of upload sample code, that you might need to adapt to the version you're running (for example this) - but you'll first need to understand that you're not looking for any representation of data on your hard drive.
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.
I'm using JFreeChart to generate a dynamic chart depending on the user input. I have a JSP with some textbox and combobox, the user makes the input and submits it, and the Action process it, generating an image of a chart. I need to display this image on the same JSP as before, below the textbox/combobox.
If I use response.setContentType("image/jpeg"); etc... then I get a page with the image alone. I thought of saving the image to a file and then access it with <img >, but I'm not sure that will work (need to save it to WebContent and I may not be able to access it always?).
Is there a way to somehow cache the image and then access it inside the JSP through an <img> or something? Maybe JFreeChart has an easy way to do what I want?
If it matters, I'm also using struts and spring on my webapp.
Thanks in advance.
I've not tried it, but you might look into org.jfree.chart.imagemap and a suitable URL generator from org.jfree.chart.urls. An outline of implementing a PieURLGenerator is illustrated here.
Well, if you generate the image on the server side, you could always just store it in a temp directory using something like a UUID to generate a unique name for it, and concatenating the image file extension on the end of it.
Make sure that the directory the image is generated is accessible on the webserver, and then send the URL path to the image file on the server back to the JSP using ajax (Direct Web Remoting), for display using Javascript.
Just make sure you also have a chron job or service to clear the older files out of the directory now and again.
You should have a servlet that can create the image you want solely from the URL. The URL can then contain an id, which maps back to an object in your program containing raw data in memory. The servlet then generates the image and returns it.
You can then simply set the url of the image in your current web page in Javascript, and it should be loaded.
This is because JSP's are character oriented which do not lend well to binary data so you need to have a servlet do it.
I am using a java applet in my web project and some images are shown in this java applet.
I want to limit users to pull images from the web page. What are possible techniques for a client user to save images used in a java applet which is used in a browser session, except "print screen"?
Any ideas are welcome.
Thanks.
..What are possible techniques for a client user to save images used in a java applet
I don't know about typical end-users, but I'd do these things to circumvent several security strategies:
1. Hide them in the archives
Look at the source of the page
Discover the location of the Jars
Download each one by direct fetch
Rename them to .zip and expand them (quick & dirty), then..
Sell your images for causing me that much inconvenience to get them in the form I want.
That last part was sarcasm (mostly), but just wanted to make the point that if you put something in a Jar, people can get it out.
2. Hide them on the server
Use a packet sniffer to discover the image locations by URL.
Pull each image directly (etc.)
3. Encrypt the images
You might use techniques to encrypt the images, then obfuscate the code that decrypts them, but that would also fail against a determined hacker.
4. Screen grab
As mentioned already. 'Last resort' - crude, but effective.
..Any ideas are welcome.
Don't pursue such strategies. You won't achieve any form of security worth having, it will just irritate the user.
If the image is a bitmap inside of a jframe it'll be hard to capture it without resorting to a screen grab. Just like using it in flash the image file itself won't actually exist anywhere on the client.
I have a JSF Web application, and at some point i present the client a big chunk of information, I want to have a save as link, that allows the client to save this information on his computer as a .txt file.
Information on how to achieve this or a good tutorial would be great.
Does this work for you? You probably would need to set the ContentType to "application/octet-stream", otherwise the client's browser will display your text file instead of offering the option to "Save as".
I believe your best bet may be to have that link actually generate an Ajax call to generate the text file and set it as the src attribute of an iframe on the page. That will trigger (I think) the file download box.