File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes uploading images using strut Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "uploading images using strut " Watch "uploading images using strut " New topic

uploading images using strut

kalpana srinuvasan

Joined: Jul 08, 2008
Posts: 9
hi.. i am using strut 1.3, i dont know how to upload images using struct in jsp page , after using <html:form action="/imgtest" enctype="multipart/form-data">, i can able to browse the image .but i have to store in the table with image column(in blob).
i write some code in action:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm imgtestForm = (DynaActionForm) form;// TODO Auto-generated method stub

FormFile myFile = (FormFile)imgtestForm.get("uploads");

byte[] ba = null;
try {
ba = myFile.getFileData();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block

Service service = null;
service = (Service) ServicesLocator.getInstance().lookUpService(Service.class);
catch (ServiceLocatorException e){

EmployeeImagesVO vo = new EmployeeImagesVO();


InputStream instr = myFile.getInputStream();

Blob blob = new Blob(byte[]);
//here is the problem .. i am not able to convert byte[] to Blob and not able to set to the column

return null;
how to proceed further..?
please help me ..
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This link has an example of uploading a file and writing it to a BLOB using Struts.

Consultant, Sima Solutions
I agree. Here's the link:
subject: uploading images using strut
jQuery in Action, 3rd edition