毕设害死人,我如何才能把服务器文件夹的文件放入数据库阿,只放路径就好,文件是图片与视频.哭哭

解决方案 »

  1.   

    简单给你一段代码自己去慢慢看!<%@ page contentType="text/html;charset=GB2312" 
             import="com.jspsmart.upload.*" 
    %>
    <%@ page import="java.sql.*"%>
    <%@ page import="java.util.*" %>
    <%@ page session="true" %><jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
    <jsp:useBean id="db" scope="page" class="oa.news.opendb" />
    <html>
    <head>
    <title>文件上传</title>
    </head><body>
    <center>文件上传</center>
    <hr>
    <% 
    String mesg="";
    String time1="";
    ........
       mySmartUpload.initialize(pageContext);   
       mySmartUpload.upload();      
       int count=0;
       String a[]=new String[3];
       String b[]=new String[3];
       for(int i=0;i<mySmartUpload.getFiles().getCount();i++)
       {
         File myFile=mySmartUpload.getFiles().getFile(i);    
          if(!myFile.isMissing())
          {

    time=year+"-"+month+"-"+day+i;

    String filename=time1+"."+myFile.getFileExt();  
    myFile.saveAs("/upload/"+filename,mySmartUpload.SAVE_VIRTUAL);       
    String path="\\upload\\";
    String fileloca=path+filename;
    a[i]=fileloca;
    b[i]=myFile.getFileExt();
    count++;  
         }else{
     a[i]="无";
     b[i]="无";  
     }
    }      .........
    String errmsg="添加成功";
    author=name+"/"+bm;
    String sql="insert into news(title,author,content,rq,class,path1,path2,path3,lx1,lx2,lx3) values('"+title+"','"+author+"','"+content+"','"+rq+"','"+type+"','"+a[0]+"','"+a[1]+"','"+a[2]+"','"+b[0]+"','"+b[1]+"','"+b[2]+"')";
    db.execQuery(sql);
    response.sendRedirect("add_news.jsp");
    }
    %></body>
    </html>