用JspSmartUpload上传图片到指定文件,并截取图片名称存入sql server2000数据库,要怎么弄啊

guaimutou 2007-06-21 08:40:05
用JspSmartUpload上传图片到指定文件,并截取图片名称存入数据库,要怎么弄啊

最好有代码 谢谢大侠
...全文
729 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
iwillrockyou 2007-06-23
  • 打赏
  • 举报
回复
smartupload的最简单用法吧。。。
hmilyld 2007-06-23
  • 打赏
  • 举报
回复
上传,获得上传后的文件名,
然后把文件名入库,就这么简单不行了?
http://hmilyld.cn/read.php?465
看下这个,
你只需要连库把最后得filename入库就可以了.
guaimutou 2007-06-22
  • 打赏
  • 举报
回复
自己顶起
fengmingjie 2007-06-22
  • 打赏
  • 举报
回复
public String upFile(byte[] fileByte,java.lang.String fileName ){
try{
System.out.println("fdjkj");
File f=new File(fileName);
DataOutputStream fileout=new DataOutputStream(new FileOutputStream(f));

FileInputStream fi=new FileInputStream(f);
int li=fi.read(fileByte,0,fileByte.length-1);
fileout.write(fileByte,0,fileByte.length-1);//这两句不能颠倒,上面依据是表示开始向fileInputStream中读入数据,这一句才是把byte[]中的数据读入到流中
System.out.println("fdjkj");
String dName="com.microsoft.jdbc.sqlserver.SQLServerDriver";
String conURL="jdbc:microsoft:sqlserver://159.164.176.116:1038;DatabaseName=Digital Lab";
// File f1=new File(""+fds.get("fileID") );
Connection con=null;
Statement stm=null;
ResultSet rs=null;
PreparedStatement ps=null;

Class.forName(dName).newInstance();System.out.println("fdjkj");
con=DriverManager.getConnection(conURL,"gaolong1","831001");System.out.println("fdjkj");
String sql="insert into testEJBFile values('"+fileName+"',?,"+(fileByte.length-1)+")";
//String sel="select * from xinxi where changhao=215;";
//String sel="select * from custom where yuming='212';";
ps=con.prepareStatement(sql);System.out.println("fdsssssjkj");
ps.setBinaryStream(1,fi,(int)fileByte.length-1);
// ps.setBytes(1,b);
ps.executeUpdate();System.out.println("fdjkj");
ps.close();
return "ok";
}catch(Exception e){
e.printStackTrace();
return "false";
}
}
}
存入数据库的方法,和上面的程序组合一下就可以了
fengmingjie 2007-06-22
  • 打赏
  • 举报
回复
package jspsmart_fileload_test;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import com.jspsmart.upload.*;

/**
* <p>Title: </p>
* <p>Description: 附件是带有 jspsmart 包,现在那个网站已经不能下载了所以这里给出 </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author wdz123@hotmail.com
* @version 1.0
*/


public class JspSmartUploadSaveServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
private static final String SAVE_DIR_PATH = "C:\\UPLOAD\\";//你可以修改这个设置,以保存到另外的目录
//Initialize global variables
public void init() throws ServletException {
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>JspSmartUploadSaveServlet</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<p>The servlet has received a " + request.getMethod() +
". This is the reply.</p>");
out.println("</body>");
out.println("</html>");
out.close();
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType(CONTENT_TYPE);
out.println("<html>");
out.println("<head><title>JspSmartUploadSaveServlet</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
saveFile(request, response, out);
out.println("<p>文件保存完成 " + request.getMethod() +
".<a href=\"jspFileLoad.jsp\">继续上传文件</a></p>");
out.println("</body>");
out.println("</html>");
out.close();
}

private void saveFile(HttpServletRequest request,
HttpServletResponse response, PrintWriter out) {
//上传的文件个数
int count = 0;
//文件描述
String FileDescription[] = {null, null, null};
SmartUpload mySmartUpload = new SmartUpload();

ServletConfig servletConfig = getServletConfig();
try {
//SmartUpload之初始化,一定要初始化才可以使用
mySmartUpload.initialize(servletConfig, request, response);
//进行相应处理
mySmartUpload.upload();
//最大文件//20mb
mySmartUpload.setMaxFileSize(20 * 1024 * 1024);
} catch (Exception e) {
}

//判断有沒有文件描述
//有保存这些信息
//沒有丟入空白字串
if (mySmartUpload.getRequest().getParameter("File1") != null) {
FileDescription[0] = mySmartUpload.getRequest().getParameter(
"File1");
} else {
FileDescription[0] = "";
}
if (mySmartUpload.getRequest().getParameter("File2") != null) {
FileDescription[1] = mySmartUpload.getRequest().getParameter(
"File2");
} else {
FileDescription[1] = "";
}
if (mySmartUpload.getRequest().getParameter("File3") != null) {
FileDescription[2] = mySmartUpload.getRequest().getParameter(
"File3");
} else {
FileDescription[2] = "";
}

//取得所有文件信息
File myFile;
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
//产生1个File对象
myFile = mySmartUpload.getFiles().getFile(i);

//如果文件存在,则把他存入指定位址
if (!myFile.isMissing()) {
try { //save file
myFile.saveAs(SAVE_DIR_PATH + myFile.getFileName(),
mySmartUpload.SAVE_PHYSICAL);
} catch (Exception ex) {
System.out.println(" error---" + ex.getMessage());
}

out.println("<font color = \"red\">您上传的第" + count +
"个的文件 :</font><BR> ");
out.println("文件名称为 :" + myFile.getFileName() + "<BR>");
out.println("文件类型为 :" + myFile.getContentType() + "<BR>");
out.println("文件说明为 :" + FileDescription[i] + "<BR>");
count++;

}
}

}

//Clean up resources
public void destroy() {
}
}

上传指定的文件
qiudawei115 2007-06-21
  • 打赏
  • 举报
回复
http://blog.csdn.net/qiudawei115,里面有一片关于这方面的介绍,基本差不多,在JSP分类里
magus163 2007-06-21
  • 打赏
  • 举报
回复
不用大侠,用baidu

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧