File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes strange problem while trying to retrieve a file url in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "strange problem while trying to retrieve a file url in servlet" Watch "strange problem while trying to retrieve a file url in servlet" New topic
Author

strange problem while trying to retrieve a file url in servlet

vignesh dhakshinamoorthy
Greenhorn

Joined: Jan 21, 2009
Posts: 12
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 ?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 21, 2009
Posts: 12
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

Joined: Sep 29, 2008
Posts: 12617

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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

See the JSP FAQ for an entry on uploading files.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: strange problem while trying to retrieve a file url in servlet