//gw_fw3.jsp
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page language="java" %>
<%@ page import="java.sql.*" %>
<body background="image/left_back.gif" leftmargin="0" topmargin="0" bgproperties="fixed">
<table border="0" height="100%" cellspacing="0" cellpadding="0" width="100%">
                    <tr>
                      <td width="65" align="right" class="unnamed2" valign="middle" bgcolor="#FFFFFF" height="22">
                      <font size="2">附件:</font></td>
                      <td width="400" bgcolor="#FFFFFF" height="22">
                      <INPUT TYPE="file" NAME="fj" style="BACKGROUND-COLOR: #ffffff; BORDER-BOTTOM: 1px double; BORDER-LEFT: 0px double; BORDER-RIGHT: 0px double; BORDER-TOP: 0px double; COLOR: #000000" size="44"></td>
                    </tr>
                 </table>
          </td>
        </tr>
      </table>
      </form>
<%
  rs.close();
  stmt.close();
  con.close();
%>
  </center>
  </div>
</td>
    <td height="98%" width="8"></td>
  </tr>
  <tr>
    <td width="1" height="5">&nbsp;</td>
    <td width="996" height="5">&nbsp;</td>
    <td width="8" height="5"></td>
  </tr>
</table>
</body>
</html>
---------------
//gw_fw4.jsp
<%@ page contentType="text/html; charset=GB2312" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date" %>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="java.io.*"%>
<%@ page language="java" %>
<%!
Connection con = null;
Statement stmt = null;
%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:newbg","sa","sa");
stmt = con.createStatement();
ResultSet rs=null;
String filename=new String(request.getParameter("fj").getBytes("ISO-8859-1"));
if(!(filename.equals("")))
{
File fileload=new File(filename);
String mywjm=fileload.getName();
FileInputStream str=new FileInputStream(filename);
String sql = "insert into bg_gw(fj,ss,wjm) values(?,?,'"+mywjm+"')";
//stmt.executeUpdate(sql);
PreparedStatement stmt=con.prepareStatement(sql);long filelength=fileload.length();
String length=String.valueOf(filelength);
stmt.setString(2,length);
stmt.setBinaryStream(1,str,str.available());
stmt.execute();
str.close();}
else
{
String sql = "insert into bg_gw(fj,ss,wjm) values('无','0','无')";
stmt.executeUpdate(sql);
}  stmt.close();
  con.close();
%>
<head>
<title></title>
</head>
<body background="image/left_back.gif" leftmargin="0" topmargin="0" bgproperties="fixed">
存盘成功
</body>
</html>
===================
再加100分。谢谢大家。

解决方案 »

  1.   

    mySmartUpload.initialize(pageContext);
    mySmartUpload.setTotalMaxFileSize(6000000);
    //mySmartUpload.setAllowedFilesList("txt,doc,xls,jpg,gif"); mySmartUpload.upload();
    for (int i=0;i<mySmartUpload.getFiles().getCount();i++)
    {
    com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);
    if (!myFile.isMissing())
    {
    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("OracleDS");
    Conn = ds.getConnection();
    medianame=myFile.getFileName();
    exname=myFile.getFileExt();
    size1=myFile.getSize();
    TypeMIME=myFile.getTypeMIME();
    SubTypeMIME=myFile.getSubTypeMIME();
    FilePathName=myFile.getFilePathName();
    Statement aStmt = Conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
    Rs = aStmt.executeQuery("SELECT MC,NR,DX,MIME,EXT FROM TEST");
    Rs.moveToInsertRow(); 
            Rs.updateString("MC",medianame); 
    Rs.updateInt("DX",size1);
    Rs.updateString("MIME",TypeMIME);
    Rs.updateString("EXT",exname);
    byte buf[] = new byte[myFile.getSize()];
    for (int j=0;j<myFile.getSize();j++) 
    {
    //out.println(myFile.getBinaryData(j));
    buf[j]=myFile.getBinaryData(j);
    }
    //File file1 = new File(FilePathName); 
           //FileInputStream fis = new FileInputStream(file1); 
           //InputStream is = fis; 
           //Rs.updateBinaryStream("NR",is,new Long(file1.length()).intValue());  myFile.fileToField(Rs,"NR");
    //ByteArrayInputStream bas = new ByteArrayInputStream(buf);

    //Rs.updateBytes("NR",buf);
    Rs.insertRow();
            Rs.moveToCurrentRow();
    Rs.close();
    Conn.close();
    out.println("FieldName = " + medianame + "<BR>");
    out.println("Size = " + myFile.getSize() + "<BR>");
    out.println("FileExt = " + myFile.getFileExt() + "<BR>");
    out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
    out.println("ContentType = " + myFile.getContentType() + "<BR>");
    out.println("ContentDisp = " + myFile.getContentDisp() + "<BR>");
    out.println("TypeMIME = " + myFile.getTypeMIME() + "<BR>");
    out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>");
    break;
    }
    }
    }