• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Aditya Sirohi
Ranch Hand
Posts: 93
Eclipse IDE Linux VI Editor
  • Mark post as helpful
  • send pies
  • 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
 
Soumyajit Hazra
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • 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.
 
Anbarasu Aladiyan
Ranch Hand
Posts: 182
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Form tag needs to have ENCTYPE="multipart/form-data" attribute
 
Aditya Sirohi
Ranch Hand
Posts: 93
Eclipse IDE Linux VI Editor
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Han Jie
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!