• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Uploading Files in jsp

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I need to upload files from a jsp page and later FTP them to a particular location from the sevlet which the jsp calls.
The problem is that I'm not allowed to use <input type="file"..> which would have made my job a piece of cake
Instead the requirements state that the user will manully enter the name of the file(s) in a text area on the jsp page
I now require to somehow send the contents of these files back to the server so that my servlet can pick up the contents of the file and then do a FTP.
I am all at sea on how to do this.Any suggestions would be of immense help and any piece of code even better
Thanks in advance!
Sunetra.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"bojo clown",

We're light on rule here at the JavaRanch, but we take the display name rules quite seriously.

We require display names to be two words: your first name, a space, then your last name. Fictitious names are not allowed and accounts with invalid display names get deleted. Please edit your profile immediately.

thanks,
Dave.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Browser security limitations prevent anything except 'file' input types from accessing the client file system, so you're starting with one hand behind your back. Preventing you from using this is crazy and you can tell them I said so

The only other option I can think of is a signed applet. If you sign the code and they accept the applet certificate it will be able to access the client file system.

Strange solution for something which is already catered for...
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that I'm not allowed to use <input type="file"..>

Why???

To add to David's comments:
The 'file' input type is the ONLY way for a user to send a file from the client to the server in a web app. Once you start adding smart client components, it's not a pure web app.
 
Sunetra Sen
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick response!
Let's see if I can persuade them to go back to input type="file"..
meanwhile can this functionality be achieved in any way without using input type="file" OR signed applet if I go for XML/XSLT
Thanks,
Sunetra
PS:I have edited my diplay name and it should show up properly soon
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sunetra Sen:
Thanks for the quick response!
Let's see if I can persuade them to go back to input type="file"..
meanwhile can this functionality be achieved in any way without using input type="file" OR signed applet if I go for XML/XSLT
Thanks,
Sunetra
PS:I have edited my diplay name and it should show up properly soon



The 'file' input type is the ONLY way for a user to send a file from the client to the server in a web app


BTW: Did they give you any reason for not wanting to use the file, input type? I can't think of any valid reason for such a requirement.
[ February 17, 2005: Message edited by: Ben Souther ]
 
Sunetra Sen
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah they did..
It seems that the end users may upload any number of files at a time say 2,5 7 10 etc..
So i suggested having 5 >input type="file"...> and if the number of files required to be uploaded exceeded 5 the user could come back and repeat the process.
but the users can't so this it seems..too much pain
so the pain was transfered to me the developer..and now i am in a soup
anyways thanks for the quick replies!

Sunetra
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could always build the <input...> fields dynamically, either on the server or using DHTML on the client. Then they could add as many file fields as they like.
 
Sunetra Sen
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have been thinking of a solution.
I came up with this one:
Have a <input type="file"..> in the page.Have one add button and a text box.
Whenever the user clicks on the add button submit the page and upload the file to a particular directory in the web server.
Then redirect back to the same page.
Now each time the page loads somehow get the list of the files names of the files stored in that particular folder of the webserver.
This way the user will feel as if he is adding the names of the files to the text area after browsing for those.
But actually we will be uploading files one at a time.Finally on click of some button ,say submit,on the jsp page all the files stored in the particular location in the webserver gets FTP'd or whatever.
Does this sound feasible to you?
Please post your thoughts on this.

Thanks,
Sunetra.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sunetra Sen:
Now each time the page loads somehow get the list of the files names of the files stored in that particular folder of the webserver.
This way the user will feel as if he is adding the names of the files to the text area after browsing for those.



It can't be done this way, and you may not be able to dynamically add file input fields.

The 'file' input type has heavy security measures, and as such you cannot pre-populate the value in the form in any way and you cannot get a directory listing in client side JavaScript. Sorry, it's just too insecure.

There's no getting around the fact they will have to select each file manually, but the plus side is that the file selector usually remembers the last directory, so that'll make it easier.

---

Another advantage to file input over applets is that if the page is secure so is the file transfer, while the applet communication may not be unless specified separately.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David O'Meara:


It can't be done this way, and you may not be able to dynamically add file input fields.

The 'file' input type has heavy security measures, and as such you cannot pre-populate the value in the form in any way and you cannot get a directory listing in client side JavaScript. Sorry, it's just too insecure.

There's no getting around the fact they will have to select each file manually, but the plus side is that the file selector usually remembers the last directory, so that'll make it easier.

---

Another advantage to file input over applets is that if the page is secure so is the file transfer, while the applet communication may not be unless specified separately.



You can dynamically add input fields but can't populate them. The only way to populate them is for the user to do it.

I have a form with DHTML that allows a user to click an "Add File" field to create as many input fields as s/he likes.
 
You have to be odd to be #1 - Seuss. An odd little ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic