Showing JFree chart image from local machine in a web application - java

I am generating a chart using JFree charting library. After generating it, I am saving it to the local machine(The requirement document specifically reads that I have save it in local machine).
Now there is an a drop down in the Web UI, to export the generated image to excel or to render the image in Web page itself.
Since I am saving the image in the local machine, the img src html tag, does not work.
Is there any way to get around the problem ?
Server used : Weblogic

You need to programatically read the contents of the file from the disk and serve it through some servlet using stream , and set the url of the Img tag in page to this servlet .

Related

Download PDF file for offline viewing

I'm trying to cache PDF files on the user's device and open them within my app at a later time.
With this package: https://github.com/barteksc/AndroidPdfViewer
I use pdfView.fromUri(uri) which loads the file from the URL every time the page is loaded.
Is there a function I can use to cache these files for offline viewing?
Download the PDF yourself, using your favorite HTTP client API. Then, use fromFile() rather than fromUri().

Retrieving data from web browser's download manager using java

I want to try creating a program that can automate the storing of web address that is available on every downloaded file on a web browser.
My problem is I don't know where to start.
What am I planning to do is just save all the downloaded file's web addresses in a excel file.
Sample image using google chrome
I think Firefox stores the download history in the places.sqlite file in your Profile folder. You would need to open and read that file, but you probably can't while Firefox is open (it has the file open).
http://kb.mozillazine.org/Places.sqlite
From there, you can process the data in your Java app and then write an Excel file, perhaps using Apache POI (the Java API for Microsoft Documents)
https://poi.apache.org/
Where and how, download history is stored varies from browser to browser . In case of Chrome on Mac it is store in the path
~/Library/Application\ Support/Google/Chrome/Default/DownloadMetadata
as SQLite format.
You need to write an application to parse the data and create xls

Java Web App outputs an image (.png) - I want to save it somewhere online and then access it

My java web app is currently hosted on Amazon (Elastic Beanstalk cloud).
A user clicks a "create image" button on the index jsp and my application generates an image with some math and then
ImageIO.write(result, "png", new File(generatedImageFilePath));
This worked fine writing from my localhost to my desktop. But now I need it to write to a file online.
How would one go about doing this?
I tried saving the created image to the path of an image that i uploaded to my Amazon Elastic Beanstalk web application environment but it doesn't overwrite the file. Do I need to find some special service to do this and give write capabilities to the application?
The other "possible" option is to just use the ImageIO.write(result, "png", new File(generatedImageFilePath)); to write to a file location inside my WAR. I'm struggling to test this because
a) I'm not sure the syntax to point to something inside my own application file structure.
b) I'm not sure if the file will be accessible to the application's ImageIO.write whilst the application is running/hosted.
I tried putting a sample resultimage.png in my animelist1/Source Packages/mainClasses directory next to my classes and tried
String generatedImageFilePath = "resultimage.png";
(do stuff)
ImageIO.write(result, "png", new File(generatedImageFilePath));
but the image didn't get overwritten.
If this is impossible then I will try to hunt down a way for me to save an image to my web host (Amazon) whilst keeping it accessible to my web application (for both writing and reading). ANY ideas or pointers would be really appreciated. I am so close to finishing this now! keeps plodding on
I'm going to have a break then see what I can make of this http://docs.aws.amazon.com/AmazonS3/latest/dev/llJavaUploadFile.html

Streaming HTML file along with images using java

I have a HTML file which has images. I want read this file from local folder like C:/data using java and display it on browser along with images when request comes from client(other than localhost).

How to save content of applet in jsp to database using servlet programming

I am developing a jsp which contains a applet which captures the image from webcam and shows in same applet.What my need is to save captured image in database through jsp form submit with some other request parametera.Until now i did it by saving the captured image in user directory of local system and then i am reading it form local system directory and then i am using JDBC PreparedStatement.
Now What my need is to to save the Captured Image in Applet with out saving it to local directory.Is it possible to read applet content through the streams?
Thanks in advance.
If I'm reading your question correctly, you're looking to save images in a database instead of the user's local file system. This is certainly possible - though I'd usually recommend storing only metadata about the images in a database, and keeping the images themselves on a file system. In your case, this would probably mean the file system of a server, and not the local desktop running the applet.
If you do want to save the images in the database, JDBC would allow for this. You'll need a database column of a BLOB (binary large object) type, and use the getBlob/setBlob JDBC methods.
Regardless of whether you decide to store the images in a database or the file system on the server, keep in mind that applet security will require your applet to only communicate with the host that the applet is being served from - so you need to host the database or proxy the database connection through the same server that the applet is being served from.

Categories