Unicorn008(菜之鸟) 加油呀!等着呢!

解决方案 »

  1.   

    最好不要把图片直接放到数据库面,会影响速度,放路径吧,我这里有程序,是使用smartupload的,而且为了防止图片重名,把图片更名为当前的系统时间。
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" %>
    <%@ page import="com.jspsmart.upload.*"%>
    <%@ page import="java.text.SimpleDateFormat"%>
    <jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
    <%
    mySmartUpload.initialize(pageContext);
    mySmartUpload.upload();

    java.util.Enumeration e = mySmartUpload.getRequest().getParameterNames(); int k=0;
    String truevalue[];
    truevalue=new String[11];

    while (e.hasMoreElements()) {
    String key = (String)e.nextElement();
    String[] values = mySmartUpload.getRequest().getParameterValues(key);
    truevalue[k]=values[0];

    k++;
    if (k==11){ int count=0; 
    for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
    com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
    if (!myFile.isMissing()) {
    SimpleDateFormat formattime=new SimpleDateFormat("hhmmss");
                SimpleDateFormat formatdate=new SimpleDateFormat("yyyyMMdd");
                String filename=(String)formatdate.format(new java.util.Date())+(String)formattime.format(new java.util.Date())+"."+myFile.getFileExt();
    myFile.saveAs("/upload/" + filename);
    count ++;
            String strSQL="insert into yourtable(vcPath) values ('"+filename +"')";
            //out.print(strSQL+"<br><br>");
            workM.executeUpdate(strSQL);
    }
    } }
      }
    %>