Hello I’m building a web application (online store) where an admin can upload a new product.
One of the input type is a file (image of the product)
I want the images of the products to be stored in a folder, and each product will have an image associated in the database table.
My question is, how does input type=file work? I still don’t understand how when I submit the form a servlet will paste the image in the webpage folder, and how is the value (name of the image) going to be obtained to be stored in the database table?
For the other inputs i use “value” to get the info.
Thanks!
In java, its hard to do handle file uploads. But there are many libraries that do it. The most popular one is apache commons file uploads Here is an example on how to do that in java:
There are many more options that you should play around with.