UpDown upDown = new UpDown();
upDown.setName(file.getFileName());
upDown.setPath(realPath);
upDownService.saveUpDown(upDown);
return mapping.findForward("success");
}
// 下载文件
public ActionForward download(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Integer id = new Integer(request.getParameter("id"));// 根据id下载文件
UpDown upDown = upDownService.getUpDown(id);
String fileName = upDown.getName();
File file = new File(upDown.getPath() + "/" + fileName);// 下载路径
InputStream is = new FileInputStream(file);
OutputStream os = response.getOutputStream();
BufferedInputStream bis = new BufferedInputStream(is);
BufferedOutputStream bos = new BufferedOutputStream(os);
public class UpDownDaoImpl implements UpDownDao {
protected HibernateTemplate hibernate;
public void setHibernate(HibernateTemplate hibernate) {
this.hibernate = hibernate;
}
public UpDown findById(Integer id) {
String hql = "from UpDown ud where ud.id=?";
List<UpDown> list = hibernate.find(hql, new Object[] { id });
if (list == null || list.size() == 0)
return null;
return list.get(0);
}
public List<UpDown> findAll() {
String hql = "from UpDown";
List<UpDown> list = hibernate.find(hql);
return list;
}
public void save(UpDown upDown) {
hibernate.save(upDown);
}
}
package updown.domain;
import java.io.Serializable;
public class UpDown implements Serializable {
private static final long serialVersionUID = 1L;