大家好,我正在开发基于动态web的应用程序,因为我正在使用struts-2文件标记来获取fileImage文件。这是代码
<s:file name="userImage" label="User Image" />现在我的pojo类代码在这里..。
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;
}
}现在在行动课上这样的代码.
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;
}
} 现在,我想使用hibernate将图像文件存储到数据库中,在数据库中,我将属性映像创建为BLOB数据类型,因此请任何一个人帮助我在执行方法中编写哪些代码,以便将图像存储在数据库中,以及如何检索它并在jsp中显示它……
提前谢谢
发布于 2014-09-11 14:17:27
我想更正一下你的代码。当您使用模型驱动的方法时,不需要为模型对象获取和设置。删除这些。
public FileUpload getUser() {
return user;
}
public void setUser(FileUpload user) {
this.user = user;
}只有以下几点就足够了
public Object getModel() {
return user;
}https://stackoverflow.com/questions/9139192
复制相似问题