• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

uploading images using strut

 
kalpana srinuvasan
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 ..
 
Merrill Higginson
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic