If you are able to store the picture as BLOB in the database, then, you can use any of the approaches to display the image.
1. use the controller to retrive the BLOB and create a image inside your webapps/images (or any folder) and pass this path to JSP to display the image.
2. stream the image in jsp, using the tag.
can you show me some examples for the first approach. actually i am first time using the springs and hibernate and don't have idea of syntax for retrieving image using hibernate and how to display that on the jsp page.
As I said, the choice of build tool is not germane to the problem. If you're using Ant, or Gradle, or some other tool, that has no bearing on the solution. You will have to adapt the tutorial for that tool, obviously.
If you're saying that that's what you're struggling with, then I think you may have bitten off more than you can chew at the moment. In that case, start with a simpler case, mybe create a desktop app that reads a file, stores it as a BLOB in the DB, and then reads it back and creates a new file from it. Leaving out the entire web app aspect simplifies things a lot, and will learn the file handling and Hibernate parts of it.
Maybe try a little harder? If I search for "hibernate blob tutorial" I get plenty of relevant results.
And I still think you could just as well follow the tutorial Prasad linked to. Since you're just learning, the choice of build tool really does not matter. After you have learned how this works, you can always adapt it to whatever build tool your team uses.
If you are looking for someone to give the code to you, you are in the wrong place.
If you want to serve up an image through a servlet, what you do is retrieve the contents of the blob into memory as a byte array, and then write it to the servlet's output stream. Also set the request's content type to match the content type of the image. So, if the image is a JPEG, you have to set the content type to image/jpg
If you are using spring mvc, add HttpServletRequest and HttpServletResponse as parameters to your handler method. Spring will automatically pass you the request and response if it sees it in the method
Btw, are you already using spring mvc, or are you looking at spring mvc just to serve the image from database. I wouldn't recommend adding spring mvc just to serve the image. It's as easy to do it in a servlet.
Figuring out why something doesn't work is the essence of debugging; surely everyone can use a bit of sharpening their skills at that. If you have concluded that examples others have come up with aren't your style, then you can start off with the basic Hibernate app I suggested earlier.
Right. A lot of young programmers tend to think that programming means googling around for solutions, copy-pasting them when you find it , and getting stuck when you don't find a solution. To many of us old-timers that is the very definition of throwing up hands. Programming doesn't mean googling and copy-pasting. It means understanding the tools and techniques, and then figuring out a way to make those tools and techniques solve a specific problem. There was a time when there was no blogs, no Stack Overflow. Heck there was no Google, and we had to learn an API from a book... A BOOK!! Eventually, at some point in the future, the people who figure stuff out and put them on blogs are going to either retire or die, and then there will be no one left to write the blogs that you can copy-paste from.
Hold on you are confusing me now. I thought you wanted to retreive an image from a database and show it to the user. But the code that you posted allows the user to upload a file that you save to a folder on the web server
no actually previously i was thinking to insert image directly into database but now i decided to insert image path in the database and image on the system as i couldn;t find out how to insert value in the database using spring hibernate
but this i have done through servlets previously so i am now trying that.