This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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
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
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.
 
Marshal
Posts: 67239
170
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.
 
You are HERE! The other map is obviously wrong. Better confirm with this tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!