Note that there are some explanatory texts on larger screens.

plurals
  1. POstoring image into mysql database using stuts 2 and hibernate
    text
    copied!<p>Hi Everyone I am developing dynamic web based application in that i am taking file[Image file] using struts-2 file tag.. here is the code </p> <pre><code>&lt;s:file name="userImage" label="User Image" /&gt; </code></pre> <p>now my pojo class code is here....</p> <pre><code>public class FileUpload { private File userImage; //private String userImageContentType; private String userImageFileName; //private HttpServletRequest servletRequest; public File getUserImage() { return userImage; } public void setUserImage(File userImage) { this.userImage = userImage; } public String getUserImageFileName() { return userImageFileName; } public void setUserImageFileName(String userImageFileName) { this.userImageFileName = userImageFileName; } } </code></pre> <p>Now in action class the code like this.....</p> <pre><code>public class FileUploadAction extends ActionSupport implements ModelDriven{ private FileUpload user = new FileUpload(); public FileUploadAction() { } public Object getModel() { return user; } public FileUpload getUser() { return user; } public void setUser(FileUpload user) { this.user = user; } public String execute() throws IOException { try{ String filePath = ServletActionContext.getServletContext().getRealPath("/"); System.out.println("Server path:" + filePath); File fileToCreate = new File(filePath, user.getUserImageFileName()); FileUtils.copyFile(user.getUserImage(), fileToCreate); } catch (Exception e){ e.printStackTrace(); //addActionError(e.getMessage()); return INPUT; } return SUCCESS; } } </code></pre> <p>now i want to store the image file to database using hibernate and in database i created attribute <strong>IMAGE as BLOB datatype</strong> so could any one please help me what is the code to write in execute method so that image to be stored in database and also how to retrieve it and display it in jsp.....</p> <p>Thanks in Advance </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload