• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

uploading images using strut

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
This link has an example of uploading a file and writing it to a BLOB using Struts.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!