• 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

uploading images using strut

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
System.out.println("sze:"+myFile.getFileSize());


byte[] ba = null;
try {
ba = myFile.getFileData();
System.out.println("dat:"+ba.length);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

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

EmployeeImagesVO vo = new EmployeeImagesVO();
vo.setEmpimgbu("MSIL");
vo.setEmpimgempid("999");

//vo.setEmpimgimage(ba);

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
vo.setEmpimgimage(blob);
service.addEmployeeImages(vo);


return null;
}
}
how to proceed further..?
please help me ..
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This link has an example of uploading a file and writing it to a BLOB using Struts.
 
reply
    Bookmark Topic Watch Topic
  • New Topic