How to use Flex and Java to download files from a server? - java

I'm building a Flex web application where there is an option to export data from a table to a CSV format (theoreitcally, so far, haha). Since it's a web application, I assumed the best way to go about this would be to send a request to the server to generate the file, and then either send that file (or a link to it) back to the Flex application, and use a FileReference to download the file. Is this the correct way to go about this?
Could anyone give me some pointers on how to do this, however? There are some exisitng remote objects in place that call Java functions on the server, so I thought I'd try something along those lines?
I did a bunch of research, and stumbled across things like HttpResponses and HttpServletResponses in Java, but have no idea how to bridge the gap between the client-side and server-side to use that effectively. Haha.
Thanks!

What I have done is have Flex open a new tab/window and navigate it to a servlet.
navigateToURL(new URLRequest(url),'_blank');
Then use a HttpServletResponse to write the file out to the client, which will then be displayed in the browser. This was for a PDF, though.
In order to use an HttpServletResponse you'll need to write a HttpServlet and configure it in your web.xml. Here is a basic tutorial. Google has a lot more.

Related

How to rewrite csv file on client with java web application

I am new in java web application, (Java EE, JSF).
I tried to change the contents of a csv file on the client computer with a java web application, so that the client does not have to download a new file, because the file is already in the set to be used for applications in the client. so I just wanted to rewrite the csv file.
Could it be done in java web application? If yes, please give me an example. I am very grateful if there is a better solution.
No, absolutely not. You can't change the contents of a file on a client computer from a web browser. The best you could do is have them upload a version of a file and then send them another version to download. Giving write access to the filesystem would be a massive security hole.
Place the CSV on a network share somewhere. The client can edit it, the back-end server can edit it. Requires more infrastructure, of course, but may work depending on the type of application.
Not that I think this is what you want, but if the 'client computer' was also acting as the server (i.e. was the host running Jetty/Tomcat/whatever), then you could modify files on it using the java IO api.
Again, very likely not what you want, just saying it would work.

In java web setups, how to implement TXT/CSV downloads?

for example, I am already at the backend and I have data (List of SomeObject) and I want it to be downloaded (instead of redirecting to a page). I am not really sure how to implement it.
QUESTION:
Am I supposed to create an actual CSV file first (in the server) and let the user download it, (delete after download) or is there a way to let the user download it without making any physical file?
Anyone familiar with cubby? or Java web Actions / ActionResults? I can't seem to get the Request/Response objects in the server actions :/ Thanks.

Uploading multiple files on the server Using JSP

I have often wonder how Facebook is able to handle uploading multiple files on the server when I am uploading my pictures.
I am quite not sure how it is being implemented. As I know, you could only send one file to the server through http one at a time unless you are going to make use of Applets.
Does anybody know how Facebook implements this? Is this Flash or an applet or something?
There's nothing special that you need to do on your web page - multiple <input type="file"> elements in the same <form> will upload multiple files at once.
The tricky part is handling all those files on the server. Take a look at a library such as Apache Commons FileUpload
Edit
You might want to take a look at this thread - people have suggested quite a few readily available components that you can use (note that these are for the client-side i.e. in the browser. You still need to handle the uploaded files on the server using something like the FileUpload library I mentioned before)

Sending HTML Form Data to Java

I have a Java program that I'm trying to interact with over the web.
I need to gather form data from the user on a Drupal site that I don't have any control over, send it to the Java program, and send the output back to the user. The Java program needs to load a lot of libraries every time it's run, so it needs to be up waiting for data from the user.
It'd be best for me to just have an HTML form for the input. What's the simplest way to deal with HTML form data using Java?
Also, I'm trying to call the Java program from a shell script. I want the program running in the background though so the libraries are loaded in advance. So ideally, I could use the server I set up for both applications.
Thanks for any help.
It sounds like you really just want to write a servlet (or use a higher level web framework, but a servlet would work fine). That makes it very easy to get web form data - you just ask for values by name, basically.
You could then "script" the application using curl, wget or something similar to make requests to the servlet.
Apologies if this doesn't answer your question - I'm finding it slightly tricky to understand exactly what you're trying to do, particularly as there are multiple layers of web UI involved, as far as I can see.
The easiest way to make POST requests with java is to use the Apache HttpClient or the more recent HttpComponents libraries.

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