How could I upload/download a file from a jsp page?
Hello all,
I want to upload/download a file from a jsp page. For the upload I have the 'input type="file"' tag included in the form, but I don磘 know how should I do now, which 'action' should be followed?.
For the download, I think I could use the onClik='XXX 'ftp://location'
I have another related question:
I need to do some OS level operations on the server, depending on the user actions( for example, create a folder, etc.. ) I worked with ASP previously and for working with the OS operations we have the Scripting.FileSystemObject object.
Is there any thing like this?
Any idea?
TIA
It's just normal Java there.
File myFile = new File("/this/is/the/location/of/your/file");
FileReader in= new FileReader(myFile);
int c;
while ((c = in.read()) != -1)
out.print((char)c);
But be sure to have: response.setContentType("application/msword");
or whatever your file type is before the File codes.
Hope this helps,
:) Ronnie
> Hi ronnie,
> what I need to do is to upload the file from one
> location to another that could be in the server or in
> a different machine.
> I think that this isn磘 possible with the file class,
> isn磘 it?
> Thanks
I am not clear on what exactly you are trying to do. Can you be a little more specific? But from what I understand that you're doing. Yes, it's possible using the File class.
jspSmart has a free upload component you can use for HTTP file uploading. Price is right!
(www.jspsmart.com)
Also, O'Reilly has an open source package you can use as well. (www.oreilly.com or www.servlets.com)
Another option is dotJ, which has custom tags that do the same thing. They also have alot of functionality that compares to some of the Microsoft ASP stuff.
(http://www.dotjonline.com)
Hello and thanks,
I have inserted the bean and jsp page and it works. But there is one problem, when I access the web page from a different computer that the server, if the filename is larger than 21 characters, it is cut to this lenght. But when executing from the server, the name isn磘 cut.
I have tried it with different machines and browsers, It磗 strange, isn磘 it?
Thanks a lot