• 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

Display an image path

 
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
i want to do the followings:
-When i press "choose the Image Path" a window open like a picture 2.
-I want also satisfy the condition written in red.
Could you help me,Thank you in advance :)
addcategory.png
[Thumbnail for addcategory.png]
fenetre.png
[Thumbnail for fenetre.png]
picture 2
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can hint to the browser to user certain file extensions:


The browser is free to ignore you so you'll have to re-validate the extension in your servlet as well. Take a look at commons-fileupload to validate the size of the file.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for you reply, that's what i exactly want :)
But, could i replace "Choisissez un fichier" and "Aucun fichier choisit" by other words ?
Also the size of the button and the text area ?
test3.png
[Thumbnail for test3.png]
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i enter a path of an image,the console display an exception:
java.io.FileNotFoundException: smartphone.jpg (Le fichier spécifié est introuvable)
what's the problem? :(
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you're using a relative path - that doesn't work in web apps, you need to use absolute paths.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i change this?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"smartphone.jpg" is a relative path (and thus relies on the default directory, which doesn't exist in web apps). An absolute path starts at the root of the file system. The ServletContext.getRealPath method can help constructing it.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code in servlet:

and this from jsp page:

Also an exception appears :
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. So that says the file you asked for can't be found. The error message gives you the full path to the file you asked for, so you should be able to confirm that quite easily.

But this whole thread confuses me. You started out by displaying some screenshots where you were asking for a file name and path (I think). And then suddenly you switched to asking a question about a servlet running in a Tomcat server which is trying to read a file from the server. I don't understand how the two things are connected.

It almost looks like you're making the typical beginner mistake about file uploads where you try to just send the client's file path instead of sending the contents of the file, and expect the server to be able to read the data from the client. But then you didn't say anything about what the purpose of your code was, so it's a mystery.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Is "C:\Users\Sarra\workspace_new\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Gestion de stock\ImagePath" an existing file or directory?

1a) If yes, does the user account under which the servlet container is run have access rights to it?

1b) If not, why is the code trying to access it?

2) It seems a bad idea to muck around with files somewhere deep inside Eclipse's directory hierarchy. (I also think it's not a good idea to run the servlet container inside of an IDE - I advise to switch to a standalone servlet container instead.)
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Okay. So that says the file you asked for can't be found. The error message gives you the full path to the file you asked for, so you should be able to confirm that quite easily.

But this whole thread confuses me. You started out by displaying some screenshots where you were asking for a file name and path (I think). And then suddenly you switched to asking a question about a servlet running in a Tomcat server which is trying to read a file from the server. I don't understand how the two things are connected.

It almost looks like you're making the typical beginner mistake about file uploads where you try to just send the client's file path instead of sending the contents of the file, and expect the server to be able to read the data from the client. But then you didn't say anything about what the purpose of your code was, so it's a mystery.



I just want to retrieve the name that I typed in the text box and also retrieve the image path chosen, it is clear at the moment is not it?
The question arises, why do I want this?
For just recorded in the database as it contains an array of column 3: id that auto increment, a name for the category and finally the image.
Part of jsp page matching the image above :

And part of the servlet to get the name and imagePath :

The problem is here :
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Still not clear. You didn't say anything about the "image path". Apparently the images are stored in database records somehow (you didn't say how -- the name of the image or the image itself?) but what's the image path? Is it a path on the client machine or on the server? And if it's on the server, why is the client allowed to choose it?

And also, why is a servlet called AddCategory trying to read a file from the server?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I answer you right away.
Well, I created a web page that only an administrator can connect.
The administrator connects to its own mahine, and can handle the addition and deletion of classes remotely.
So, the administrator is the one who made ​​the choice of the name and the image.
About the servlet, I did not understand what just tell me.
Is that clear maintenat?
For me, I just Volut retrieve the path of the image chosen.
I tried to do as follows and I managed to add the image and name:

test4.png
[Thumbnail for test4.png]
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarra Sakka wrote:Well, I created a web page that only an administrator can connect.
The administrator connects to its own mahine, and can handle the addition and deletion of classes remotely.



So the administrator is required to do this on the same machine as where the Tomcat server is running? That's a strange design but not completely out of the question.

For me, I just Volut retrieve the path of the image chosen.



What do you mean, "retrieve" it? The administrator is going to have to type it into the field.

And by the way your code only allows 20 characters for the path. I don't think that's nearly long enough.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The administrator can manage application either on the same machine or on another machine though.
the administrator will choose the image.
"retrive it": I mean how can i get the path of image chosen by admin in servlet.
About the size, it's a mistake, i must remove it.
Please, Could you please give a solution?
thank you in advance :)
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:1) Is "C:\Users\Sarra\workspace_new\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Gestion de stock\ImagePath" an existing file or directory?

1a) If yes, does the user account under which the servlet container is run have access rights to it?

1b) If not, why is the code trying to access it?


Yes, it's a existing directory, and the user have access rights to it


2) It seems a bad idea to muck around with files somewhere deep inside Eclipse's directory hierarchy. (I also think it's not a good idea to run the servlet container inside of an IDE - I advise to switch to a standalone servlet container instead.)


How can i do this ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If by "path of image chosen" you mean the client-side path to the image chosen during the HTML file upload, then that is not possible, period. Browsers send the file name, not the path. You will have to come up with a different design.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sarra Sakka wrote:

Ulf Dittmer wrote:I advise to switch to a standalone servlet container instead.)

How can i do this ?


Download Tomcat and follow the instructions on the web site - they are quite extensive.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:If by "path of image chosen" you mean the client-side path to the image chosen during the HTML file upload, then that is not possible, period. Browsers send the file name, not the path. You will have to come up with a different design.


When i use a simple input < type="text"..> it work, the problem with the <input type="file"...>.
When i use <input type="text" ..>, i can get the path in the servlet and it will be stocked in database.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If that solves the problem, and the users think that entering the full path manually is an acceptable solution, then all is well, yes?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I don't want the solution that enter the full path manually :/
I want the solution like the above image "test3"
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's too bad. You already have a questionable design, as you can tell by the fact that HTML doesn't support what you want to do. I would suggest redoing your design to something more normal.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's your suggestion about a new design ?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's too early for me to suggest any design because I don't know what the requirements are.

And you shouldn't tell us that the administrator has to use the machine where the server is running or anything like that. So far all we have seen are failed attempts to implement the unknown requirements. You should tell us things like what data is required.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want a solution please;
My goal is when i click on "choisissez ....", a window opens to select the desired picture.
Then, the path of the image chosen will be stored in the database.
I don't know why it's no clear :/
test3.png
[Thumbnail for test3.png]
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is clear, but it is impossible, as was pointed out before. The alternative -entering the entire path by hand- according to you works, but is not acceptable (which I understand, it's bad usability).

So there is no solution to the problem as posed by you. We may be able to help if you take a step back and describe the larger issue at stake; maybe it lends itself to other approaches.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply :)
Well, I created a database that contains a table category, formed by three column:
id, category_name, category_image.
I want to fill this table from the web application, which is accessible except for the admin.
This what i want exactly.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So where does any kind of file path come into play? This entire discussion seems to have been about storing a path in the DB, but the schema doesn't have one? For uploading an image (which is what *is* in the schema) I don't see why any kind of path would be required.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Admin will enter the path of the image located in its own machine,
Like in this forum, in the Attachements window, i choose the image from my pc and i submit it.

This entire discussion seems to have been about storing a path in the DB, but the schema doesn't have one?


Yes, the problem is how can i store a path in a DB from
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question is: why does the path matter? You need the image, right? Why would you care where it was stored on the client? The image gets uploaded, and then stored by your code wherever it makes sense on the server. After uploading, the path where the image was stored on the client becomes completely irrelevant.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need the image, yes that's what i want.

Why would you care where it was stored on the client?


So, should i don't care ?

The image gets uploaded, and then stored by your code wherever it makes sense on the server


How can i do this ???
Could you please give me a solution, because the mine it's impossible, i'm stuck :(
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if you don't even know why you should care about the path, I think it's safe to say that you haven't thought this through.

I suggest to start by learning how file upload works in general. Download the Apache Commons FileUpload library, I seem to recall that it comes with extensive documentation and examples.
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please give me some links
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should be able to search for "Apache Commons FileUpload library" on your own, no?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, thank you :)
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's no a solution other than FileUpload ?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's wrong with it?
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing,
it's new for me and i don't know it :D
 
Sarra Sakka
Ranch Hand
Posts: 283
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a question: should i download a library or something else to make FileUpload work?
 
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic