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

[647 byte] By [beamar1a] at [2007-9-19]
# 1
For download you can use <a href="yourfile.txt">Here click to download</a>To work with files, directories etc....use Class File.hope this helpTomas
tomikva at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 2
HelloIs this class File accesible from a jsp page?Thanks
beamar1a at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 3

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

rhibiscusa at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 4
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
beamar1a at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 5

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

rhibiscusa at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 6

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)

jpardia at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 7
hi,have a look at http://www.oreillynet.com/pub/a/onjava/2001/04/05/upload.html . Here you can find a upload-bean.
ricopauw1a at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 8

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

beamar1a at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 9
See Coldtags suite for Upload, Download and File taglibs: http://www.servletsuite.com/jsp.htm
dnamiota at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 10
I have a similar question. Using Java, how do I ftp a file from a servlet to another compute?
teutonica at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 11
I'm using an FTPClient class. It provides methods for common ftp operations (cd, ls, get, put...)You can download it from: http://www.enterprisedt.com
jorgevadilloa at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 12
give me answerr anyone?
ziaansaria at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 13
give me answerr anyone?
ziaansaria at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...
# 14
For Upload you could try UploadBean : http://www.javazoom.net/jzservlets/uploadbean/uploadbean.htmlFor Download you could try Download4J : http://www.javazoom.net/jzservlets/download4j/download4j.html
javazooma at 2007-7-8 > top of java,Enterprise & Remote Computing,Web Tier APIs...