• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Issue with the Browse button(<input type="file">)

 
Ranch Hand
Posts: 93
Eclipse IDE VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

This is my first post regarding JSP issue. I am trying the following scenario:-
1. User can enter the path to the a file using the <input type="file"> in code.
2. After hitting the Submit button, user can see the content of his file on the web page.

So i have written two JSP files for it, i.e. index.jsp which looks like



Content of display.jsp looks like



But the issue is when i hit the Submit button it says "File not found" what can be the issue?. Is there any way i can find the value of "inputFileElement" in the display.jsp file? Also if in the index.jsp file if i change the input type="text", it works fine, but i want a browse button there.

Thanks
Adi
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Buddy your code is working fine in my system. I have not changed a single line of code. Try printing the filePath variable and see what path it is showing.
 
Ranch Hand
Posts: 182
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Form tag needs to have ENCTYPE="multipart/form-data" attribute
 
Aditya Sirohi
Ranch Hand
Posts: 93
Eclipse IDE VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Soumyajit/Anbarasu,

First question, it might sound dumb:- How do i print the value of of filePath variable? I did the following changes to display.jsp to print its value, but cant see it,



@Anbarasu - Adding ENCTYPE="multipart/form-data" attribute to form tag gives Null pointer exception.

Thanks
Adi
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Soumyajit Hazra wrote:Buddy your code is working fine in my system.


But it will not work in general. This code is doing it wrong and will only work when the browser is being run on the server.

You need, as has already been pointed out, to use a multi-part form, and to read the file from the request not the file system. The server has no access to the client's file system. Ever.

You should read the FAQ page on file uploading.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:
But it will not work in general. This code is doing it wrong and will only work when the browser is being run on the server.

The server has no access to the client's file system. Ever.



I started a bit lost, because I run the code on my pc on which the browse and server are installed together and do not realize the hidden problem.

It indicates that the differences between browser and server are not very clear in my mind.

After Bear said, i suddenly realize it more clearly.

So, thanks verycd much.

Regards

HanJie
 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At Bear :

This code will only work when the browser is being run on the server.



What does the above mean exactly ?? How can a browser run on the server ??

Waiting for your reply . Thanks .
 
Han Jie
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran Pattu wrote:At Bear :

This code will only work when the browser is being run on the server.



What does the above mean exactly ?? How can a browser run on the server ??

Waiting for your reply . Thanks .



hi Ravi

In my opinion, it means that if the browser and server are not on one machine together, the server only get and process the file you need through it's own filesystem.

But actually, there is not the file you required on the server but only on the browser.

So in this situation, the codes in "display.jsp" work wrong absolutely.

The understanding of mine is all above and what's yours?
 
Bear Bibeault
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ravi Kiran Pattu wrote:How can a browser run on the server ??


By clicking the little icon that starts the browser.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic