How to display and update received image in jsp page - java

I'm new in web development (spring-mvc), my background is from android world. I'm receiving images from service every 2 second, than I'm saving them to the WEB-INF/images folder, at this time every 1 second, I'm making ajax request to retrieve and display received image.
This is how I'm making ajax call
function updateImage() {
$.get('/api/getCurrentImagePath/', function (frameImagePath) {
$("#targetImgView").attr("src", frameImagePath);
setTimeout(updateImage, 1000)
})
}
My problem is that, when function is invoked $("#targetImgView").attr("src", frameImagePath);
console logs http://localhost:8080/images/13456482154.jpg 404 not found error
but received image path is correct.
How can I resolve this issue? or is there any better way to do, what I'm trying to do?
P.S
when I save images into the webapp/images folder during the running server and trying to set the path of images it does not works, but if I restart the server and statically set the path of already saved images it works

In Spring MVC, we have to options to display images
From another FTP server
From within EAR, to do so you can open images placed inside resource folder
Add this entry in dispatcher-servlet.xml
<mvc:resources mapping="/image/**" location="/resources/images/" cache-period="0"/>
You need to put images in your webapp/resources/images folder. After that access the image contextPath/image/imageName.jpg

Related

JSP Website Deployment Query for Sub Domain

Thanks in advance.
I have a question with regards to Sub-Domain.
the Primary domain is www.abc.com
There is a function in JSP which creates an Image for the user as membership cards which needs to be saved and which is also getting saved in a particular folder.
The concern is that whenever I make any changes on the websites java class files I re-upload the .war file on the server which recreates all the folders and files on the server in turn what happens is that all the Images created for the user also gets deleted.
So if I create a Sub-Domain called www.members.abc.com and create a folder in it where all the created Images will be stored then when I reupload the .war file will this sub-domain and its folders get affected.

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

Java - How to programmatically download an attachment from a URL which opens a new tab?

I need to download an attachment from a URL (say http://mywebsite.com) programmatically using Java. The tricky part is that the above URL opens up a new tab/window onload from which the downloading actually starts.
E.g.
Open http://mywebsite.com
http://mywebsite.com loads and opens up a new tab to http://mywebsite.com/attachments/someRandomFileName.pdf
*Note the file name in step 2 (above) is randomly assigned so I cannot hit http://mywebsite.com/attachments/someRandomFileName.pdf directly.
Thanks in advance!
The whole point of randomly generated URLs is to prevent people to access content directly.
They probably want users to go through their web site to access the file. There are numerous ways to check that request is coming from a real user/browser. This includes executing javascript and/or flash. Random URLs are generated on server and at some point they will be sent to browser.
So basically, to download a file, you'd have to look at what their web site is doing, what kind of requests it is making and what replies it gets from servers. Then try to reverse engineer this to get directly to random URL representing the file.

identify the page load successful on the server side java

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.]

Downloading files via a webView

I am currently implementing a webview that uses the default behavior of opening the browser. When the page loads in the browser and I click the download link that is on the page that was loaded, the download starts, and quickly fails. I guess its an unsupported file type. How would I go about setting the WebView so that I may handle when a user downloads a file, and process the file myself? The reason I am going through a webview is that using httpclient, I was unable to spoof the headers after trying unsuccessfully for 30 or so hours. So what I would like to be able to do is handle the saving, and unzipping of the file myself. Can anyone write me some code to get started?
Thanks a million.

Categories