Java file upload - java

can i upload a file(image) without submitting the form..
Basically i want to create a webpage where a user can upload an image and preview it side by side but this should not submit my form.
i dont wanna use jquery

You can have two forms on the page. One to upload the image and other one for something else. Just don't nest them.

I've tried to implement this with AJAX but, if it's even possible, it would be a nasty hack. About the best you can do reasonably is to put the file upload form in an iframe, and after posting the file with AJAX, redraw the page with the image.

I think this is what you want But it uses PHP for sever side you can use what ever you want!
All you have to do is create a page which will handle the ajax call, which is saving the image and returning string "true" in case of succeeds. and for Java this (Handling Form-based File Upload with Java Servlet or JSP) should help you.
Check this one out ioncannon.net

You can try this .Also check

Related

Image Upload in Jquery using Spring?

Actually I'm doing Sample Application,
We are Observe many of social networks, in that Profile images are their, When ever mouse over it is asking Upload new Image.
So i want to Develop Same Application .
When ever we write <input type="file"/> then it is asking file and now add value(image) into .. So how to add this value.
Their is only one click browse image and upload image...
And now how to handle this one into Spring side..
Please Suggest me..
I thing you need to use ajax to do this. Click here to see a demo in PHP. They show how to done that in PHP. Instead of PHP you can use Spring with JSON to complete that.

Downloading generated excel file using ajax

I am developing an application using struts2 framework. When user provides date range, I need to prepare the reports excel file and show that in download pop-up. I am able to create io stream of excel, but I am not getting how can I open that pop-up using ajax.
I am generating file on the fly and returns the stream. Therefore not able to give file path. I want ajax call to show some message like "Please wait..". Because file generation takes more time and it looks like link is not working..
There's nothing Ajax about downloading a file.
Your request can be an ajax request, but simply give the generated file path and the browser will do the downloading.
No need to perform any AJAX calls.
You just need to return the byte[] as a Struts2 Stream result,
configured with a ContentDisposition: attachment; (and not ContentDisposition: inline, that will try to open it inside the browser instead of asking about downloading or opening with a desktop application).
To notify the user that something is going on, that the request is sent and the system is not frozen, you need an Loading OVERLAY.
An Overlay is an element that is placed over your page, generally with a partially transparent background, an animated image saying "Loading..." , and a modal behavior (it won't close until the page is changed, and it will prevent double post of the same request, like double clicks etc...).
Of course if you open an attachment, the page will not change, then you'll need to intercept the end of the downloading and close the overlay by yourself, or give the user a button to close it.
To intercept it, you can try the Struts2 Execute and Wait Interceptor.
If you want to create a custom overlay, you can generate your Loading images with the ajaxload.info Generator.
If you instead don't want to reinvent the wheel, you can take a look at existing overlays, like those from jQuery TOOLS.
On the success method of ajax do not return the stream, instead save the file on server and open a pop up with address to an action that returns correct file. But pop ups might be blocked in some browsers so you need to allow that for your site (local host or other URL)

Interact with Web Page from java

So I'm making a program for android that tries to download something from www.wupload.com. What I want isn't a browser but to interact with the webpage without actually showing it. Like how HtmlUnit is supposed to work.
I'm using apache for the html requests and what I've done so far is send a post that simulates clicking on slow download on the web page. Then I read the response so I can get some variables needed to make the next post and execute the next post. In theory, the web page should be showing the captcha cause the response I get is please enter the captcha, but no image url.
The next step would be to enter the captcha and finally download the file, the problem I'm having is I don't know how to show the captcha image to the user. Do I have to capture it somehow? I know how to make the post to send what the user would type, but the image url of the captcha isn't in the source code.
I thought of inspecting the web page so I could get the url from the DOM tree, like what inspect element on google chrome does, but I have no idea if it's even possible. Any ideas would be great.
thx
The captcha is probably generated using JavaScript. Therefore when you get the source of the website, the captcha hasn't yet been generated and you won't see the image in the source HTML. You would need to run the Javascript somehow. You could try using a WebView because it has built-in support for Javascript, or get a Javascript library for Java and use it somehow. I think it would be a lot of work.
Edit:
Actually, if they are using a thirdy-party captcha library, I'm sure it uses some sort of HTTP request system, so you might be able to inspect it with this plugin for Firefox.

Upload files in JSP/Servlet

i know how upload files in jsp/servlet, i already use fileupload from apache, but i don't know how to return some status of the upload to the user, for example, actually when someone select the file to upload, they have to click in 'upload' button and just when the upload finish the jsp page redirect to the another page.
I want they can see a percentage of how much will take to complete the upload operation.
i already implement a listener using fileupload, but i don't know how to show this information to the user, 'cause just when the upload is finished that i can redirect to another jsp page.
Any ideas ?
Best regards,
Valter Henrique.
That's not possible in combination with plain HTML <form> with <input type="file">. To the point, you've got to send multiple simultaneous requests. A form submit with file upload will namely block as long as the upload is in progress.
Your best bet is using JavaScript/Ajax and/or Flash. There are several free file upload components supporting a progress bar, like Uploadify and SwfUpload.
If your servlet is well written, you should be able to use it unchanged.

asynchronous file upload with java servlet

Here's I want to do, I want to upload a file that will be processed by a servlet. I would use Apache Commons - File Upload to handle the file to be uploaded.
I've seen the gmail-like AJAX file upload, where there would be a hidden iframe that would later be populated with a javascript to stop showing the upload image or displaying a message that the upload is succesful. However, this uses PHP, where the php file to handle the file upload would include the javascript inside the iframe.
My question is, how would I do this in Java using servlets, without resorting to JSP and imitating the above implementation on PHP. I don't even know if this is possible, so please guide me on a good implementation (without external libraries except for commons fileupload).
Note: I am aware that there are libraries out there that could do this easily, but I first want to know how this happens, how this is possible, and to dirty my hands and learn this.
Edit: Just to add, I would use the streaming API of Apache-Commons FileUpload
It is exactly the same.
The client makes an HTTP request to the server (by submitting a form).
The server responds with some HTML (which links to or embeds some JavaScript).
Switching from PHP to Java is just a drop in replacement. You don't need to change any of the JavaScript. The user guide tells you how to set it up.
http://oreilly.com/pub/a/javascript/2002/02/08/iframe.html is the best idea to file-upload. i done file upload using hidden iframe. Please consult with attached link.

Categories

Resources