?? uploadedit.jsp
字號:
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page language="java" import="java.sql.*,com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<%
// Initialization
mySmartUpload.initialize(pageContext);
// Upload
mySmartUpload.upload();
//uncomment the following to save file to upload dir also
//mySmartUpload.save("/upload");
String DBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
String ConnStr = "jdbc:odbc:files";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try
{
//加載數(shù)據(jù)庫驅(qū)動程序
Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("DBconn (): " + e.getMessage());
}
//與DBMS建立連接
try
{
conn = DriverManager.getConnection(ConnStr);
stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE);
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery: " + ex.getMessage());
}
String docid;
String filename;
long filesize;
String contenttype;
// for debug only
/*
out.println("<BR><STRONG>Display information about Files</STRONG><BR>");
out.println("Number of files = " + mySmartUpload.getFiles().getCount() + "<BR>");
out.println("Total size (bytes) = " + mySmartUpload.getFiles().getSize() +"<BR>");
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){
out.print(mySmartUpload.getFiles().getFile(i).getFieldName());
if (!mySmartUpload.getFiles().getFile(i).isMissing())
out.print(" = " + mySmartUpload.getFiles().getFile(i).getFileName() + " (" + mySmartUpload.getFiles().getFile(i).getSize() + ")");
else
out.print(" = vide");
out.println("<BR>");
}
*/
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
if (!myFile.isMissing())
{
docid = mySmartUpload.getRequest().getParameter("docid");
filename = myFile.getFileName();
filesize = myFile.getSize();
contenttype = myFile.getContentType();
System.out.println("docid="+docid);
System.out.println("filename="+filename);
System.out.println("filesize="+filesize);
System.out.println("contenttype="+contenttype);
try
{
if ( (docid == null)||(docid.length() == 0) ) // new doc
{
System.out.println("New document....");
rs = stmt.executeQuery("select * from MyUploadTable where id=1");
rs.moveToInsertRow(); // moves cursor to the insert row
rs.updateLong("filesize",filesize);
rs.updateString("filename",filename);
rs.updateString("contenttype",contenttype);
// Add the current file in the DB field
myFile.fileToField(rs,"filedata");
// insert
rs.insertRow();
}
else // edit doc
{
System.out.println("Edit document id=" +docid );
rs = stmt.executeQuery("select * from MyUploadTable where id="+docid);
if (rs.next())
{
rs.updateLong("filesize",filesize);
rs.updateString("filename",filename);
rs.updateString("contenttype",contenttype);
// Add the current file in the DB field
myFile.fileToField(rs,"filedata");
// Update
rs.updateRow();
}
}
}
catch(Exception e)
{
out.println("發(fā)生錯誤: " + e.toString());
}
rs.close();
out.println("保存的文件: " + filename + "<br>");
out.println("大小: " + filesize + " bytes<br>");
}
else
{
out.println("沒有上載的文件!<br>");
}
%>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -