aspose file tools*
The moose likes Servlets and the fly likes How to  store an image from a jsp page to Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to  store an image from a jsp page to Database" Watch "How to  store an image from a jsp page to Database" New topic
Author

How to store an image from a jsp page to Database

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

I am trying to store an image from a jsp page . I will be using setBinaryStream method from PreparedStatement ?


But how can I pass the data from jsp to the servlet ??

Any ideas or suggestions please specify.


Save India From Corruption - Anna Hazare.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


But how can I pass the data from jsp to the servlet ??

Not sure what the issue is with this- both Servlet and JSP are running on the server JVM so just pass the image as you would any other object.

Or are you asking how you upload the binary data from the client machine to the Servlet?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thanks paul for responding ,

The question is i have a User Object , in which he has Name , Age , Image


how can i send the image
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Its up to you, but a byte array sounds like a good candidate.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thanks paul ,

do i need to include byte array data type as setter and getter methods with User Object directly ??Please specify.
Nishan Patel
Ranch Hand

Joined: Sep 07, 2008
Posts: 689


Hi,

That is good way if you declare your image type to byte array like

byte[] image;

And good to make getter and setter method in User object so you cane get user.getImage() method.


Thanks, Nishan Patel
SCJP 1.5, SCWCD 1.5, OCPJWSD Java Developer,My Blog
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thank You Nishan .

I asked this particular question to include byte array[] inside the DTO because.

in a site i read this should not be a part of DTO.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to store an image from a jsp page to Database