Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

strange problem while trying to retrieve a file url in servlet  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I faced a very strange problem. Got crazy with this Someone must have a look at this.

What i am doing ?
O Read a file in a jsp page.
O Hit a servlet.
O Print the complete URL of the file.
Nothing else. Task is as simple as that.

What i wrote ?

JSP Code:(Inside form Tag)

Servlet Code: (Inside doPost)

What i got ?

Try #1:
Browser: Internet Explorer 6.
Output : URL is C:\Documents and Settings\vignesh.d\Desktop\J2EETutorial.pdf
This is what i expected.
Try #2:
Browser: Mozilla Firefox 3.x
Output : URL is J2EETutorial.pdf
you can notice that the file name alone is printed and not the complete path.

Try #3:
Browser: Internet Explorer 6. (My friend's computer)
Output : URL is null

We both are using XP & he got a null value when i got the correct output in same XP, IE 6.

What the is happening here ?

 
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know how you could get null if a file was actually uploaded, but besides that: different browsers return different things for file input elements: some return the entire local path (useless on the server side), some just return the file name.
 
vignesh dhakshinamoorthy
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David, thanks for replying.

David Newton wrote:Don't know how you could get null if a file was actually uploaded


Yeah, that's why i am

David Newton wrote:some return the entire local path (useless on the server side), some just return the file name.


Yeah, that's what happened here. I am just testing it on my local system. Not developing any enterprise application. So the "entire local path" will be good enough for me.

As i just want to input an XML file, A "file upload" functionality will solve this guess...
But i dont know how to upload file in a web application
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using a request wrapper that handles file uploads automatically? Your code implies that you do, but now I'm guessing you're not.

Google for servlet +file upload; there are a million different ways to go about this.

Also make sure your form tag is set up for a file upload.
 
Author and ninkuma
Marshal
Posts: 66801
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the JSP FAQ for an entry on uploading files.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!