ssh 实现图片的存储 一般那些购物网站的商品图片是怎样存储的啊?就是那些介绍商品的图片,网上书店,淘宝网那些一样,是直接存在数据库还是存在硬盘或是只存图片的路径? 那位仁兄能细说一下的????????????????????? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是struts实现的图片的上传和下载的关键代码:public class FileAction extends DispatchAction { private JDBConnection connection =new JDBConnection();//以下方法实现文件的上传 public ActionForward upLoadFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Date date = new Date(); FileActionForm fileActionForm = (FileActionForm) form; FormFile file = fileActionForm.getFile(); //获取当前的文件 String dir = servlet.getServletContext().getRealPath("/image"); String path = upload(dir, file); //实现文件的上传的功能,并且返回上传服务器的路径 path="image/"+path; String fileName = Chinese.toChinese(fileActionForm.getFileName()); //获取文件的名称 String fileSize = String.valueOf(file.getFileSize()); String fileDate = DateFormat.getDateInstance().format(date); String sql = "insert into tb_file values('" + fileName + "','" + fileSize + "','" + fileDate + "','" + path + "')"; connection.executeUpdate(sql); connection.closeConnection(); return mapping.findForward("upLoadFileResult"); } public String upload(String dir, FormFile formFile) throws Exception { Date date = new Date(); //取欲上传的文件的名字和长度 String fname = formFile.getFileName(); //将上传时间加入文件名 int i = fname.indexOf("."); String name = String.valueOf(date.getTime()); String type = fname.substring(i + 1); fname = name + "." + type; InputStream streamIn = formFile.getInputStream(); //创建读取用户上传文件的对象 File uploadFile = new File(dir); //创建把上传数据写到目标文件的对象 if (!uploadFile.exists() || uploadFile == null) { //判断指定路径是否存在,不存在则创建路径 uploadFile.mkdirs(); } String path = uploadFile.getPath() + "/" + fname; OutputStream streamOut = new FileOutputStream(path); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) { streamOut.write(buffer, 0, bytesRead); } streamOut.close(); streamIn.close(); formFile.destroy(); return fname; } //实现文件的下载 public ActionForward downFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String path = request.getParameter("path"); BufferedInputStream bis = null; BufferedOutputStream bos = null; OutputStream fos = null; InputStream fis = null; String filepath = servlet.getServletContext().getRealPath("/" + path); File uploadFile = new File(filepath); fis = new FileInputStream(uploadFile); bis = new BufferedInputStream(fis); fos = response.getOutputStream(); bos = new BufferedOutputStream(fos); response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(path, "utf-8")); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) { bos.write(buffer, 0, bytesRead); } bos.flush(); fis.close(); bis.close(); fos.close(); bos.close(); return null; }} 我在SSH2配置了两个applicationContext.xml连接两个数据库 如何把查询到的数据放到JSP页面 Hibernate关联表查询 jsp页中的表格内容,提交给Excel?急急急 请教一个JPQL句子 struts如何实现级联选择[数据库读的]啊,最好能有代码示范下。 jboss3.2.5 怎么设虚拟主机 比如在设在c:\pro hibernate同j2ee app server的BMP javamail拒绝发送问题 帮忙讲解一下EJB???谢谢!!! 请问哪有 DukesBank 下载? GIF的图像为什么显示不出,求高手解答
public class FileAction extends DispatchAction { private JDBConnection connection =new JDBConnection();
//以下方法实现文件的上传
public ActionForward upLoadFile(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
Date date = new Date();
FileActionForm fileActionForm = (FileActionForm) form;
FormFile file = fileActionForm.getFile(); //获取当前的文件
String dir = servlet.getServletContext().getRealPath("/image");
String path = upload(dir, file); //实现文件的上传的功能,并且返回上传服务器的路径
path="image/"+path;
String fileName = Chinese.toChinese(fileActionForm.getFileName()); //获取文件的名称
String fileSize = String.valueOf(file.getFileSize());
String fileDate = DateFormat.getDateInstance().format(date);
String sql = "insert into tb_file values('" + fileName + "','" +
fileSize + "','" + fileDate + "','" + path + "')";
connection.executeUpdate(sql);
connection.closeConnection();
return mapping.findForward("upLoadFileResult");
} public String upload(String dir, FormFile formFile) throws Exception {
Date date = new Date();
//取欲上传的文件的名字和长度
String fname = formFile.getFileName();
//将上传时间加入文件名
int i = fname.indexOf(".");
String name = String.valueOf(date.getTime());
String type = fname.substring(i + 1);
fname = name + "." + type;
InputStream streamIn = formFile.getInputStream(); //创建读取用户上传文件的对象
File uploadFile = new File(dir); //创建把上传数据写到目标文件的对象
if (!uploadFile.exists() || uploadFile == null) { //判断指定路径是否存在,不存在则创建路径
uploadFile.mkdirs();
}
String path = uploadFile.getPath() + "/" + fname;
OutputStream streamOut = new FileOutputStream(path);
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = streamIn.read(buffer, 0, 8192)) != -1) {
streamOut.write(buffer, 0, bytesRead);
}
streamOut.close();
streamIn.close();
formFile.destroy();
return fname;
}
//实现文件的下载
public ActionForward downFile(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
String path = request.getParameter("path");
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
OutputStream fos = null;
InputStream fis = null;
String filepath = servlet.getServletContext().getRealPath("/" + path);
File uploadFile = new File(filepath);
fis = new FileInputStream(uploadFile);
bis = new BufferedInputStream(fis);
fos = response.getOutputStream();
bos = new BufferedOutputStream(fos);
response.setHeader("Content-disposition",
"attachment;filename=" +
URLEncoder.encode(path, "utf-8"));
int bytesRead = 0;
byte[] buffer = new byte[8192];
while ((bytesRead = bis.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesRead);
}
bos.flush();
fis.close();
bis.close();
fos.close();
bos.close(); return null;
}}