您现在的位置: 破洛洛 >> 建站学院 >> 网站开发 >> JSP教程 >> 正文

使用Struts+Hibernate上传大对象(BLOB)(二)

作者:佚名 来源:网络整理 更新时间:2008-12-26
分享到

this.session = HibernateSessionFactory.getSession();

}

public void addPhoto(Photo photo){

Transaction tx=session.beginTransaction();

session.saveOrUpdate(photo);

tx.commit();

}

public Photo getByName(String name){

Query query=session.createQuery("from Photo p where p.name = ?");

query.setString(0,name);

return (Photo) query.uniqueResult();

}

public void close(){

if(session.isOpen()){

session.close();

session=null;

}

}

}

import org.hibernate.Query;

import org.hibernate.Session;

import org.hibernate.Transaction;

import com.hp.entity.Photo;

import com.hp.util.*;

public class PhotoDao {

private Session session=null;

public PhotoDao(){

this.session = HibernateSessionFactory.getSession();

}

public void addPhoto(Photo photo){

Transaction tx=session.beginTransaction();

session.saveOrUpdate(photo);

tx.commit();

}

public Photo getByName(String name){

Query query=session.createQuery("from Photo p where p.name = ?");

query.setString(0,name);

return (Photo) query.uniqueResult();

}

public void close(){

if(session.isOpen()){

session.close();

session=null;

}

}

}

6:struts的ActionForm代码


Java代码
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionMapping;

import org.apache.struts.upload.FormFile;

public class AddForm extends ActionForm {

//在Struts中上传文件需要使用FormFile类型

private FormFile photo;
private String name;

public ActionErrors validate(ActionMapping mapping,

HttpServletRequest request) {

return null;

}
public void reset(ActionMapping mapping, HttpServletRequest request) {

}

public FormFile getPhoto() {

return photo;

}
public void setPhoto(FormFile photo) {

this.photo = photo;

}
public String getName() {

return name;

}
public void setName(String name) {

this.name = name;

}

}

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionMapping;

import org.apache.struts.upload.FormFile;

public class AddForm extends ActionForm {

//在Struts中上传文件需要使用FormFile类型

private FormFile photo;
private String name;

public ActionErrors validate(ActionMapping mapping,

HttpServletRequest request) {

return null;

}
public void reset(ActionMapping mapping, HttpServletRequest r

转载请注明:破洛洛(谢谢合作)
网友评论: