用 smartupload .
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*" %>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<jsp:useBean id="sqlbean" scope="page" class="beans.sql_data"/>
<%
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
if (!myFile.isMissing())
{
String myfilename= null;
String sql="";
myfilename=myFile.getFileName();
String fname =myFile.getFileName();
String suffix=myfilename.substring(0,myfilename.lastIndexOf('.'));
String explain=(String)mySmartUpload.getRequest().getParameter("text");
explain=new String(explain.getBytes("ISO8859-1"),"GB2312");
String ts="/product/"+fname;
myFile.saveAs(ts);
}
<%@ page import="java.sql.*"%>
<%@ page import="java.lang.*" %>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<jsp:useBean id="sqlbean" scope="page" class="beans.sql_data"/>
<%
mySmartUpload.initialize(pageContext);
mySmartUpload.upload();
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
if (!myFile.isMissing())
{
String myfilename= null;
String sql="";
myfilename=myFile.getFileName();
String fname =myFile.getFileName();
String suffix=myfilename.substring(0,myfilename.lastIndexOf('.'));
String explain=(String)mySmartUpload.getRequest().getParameter("text");
explain=new String(explain.getBytes("ISO8859-1"),"GB2312");
String ts="/product/"+fname;
myFile.saveAs(ts);
}
www.jspsmart.com
大家用的最多
[email protected]
INDEX.HTML
<HTML>
<BODY BGCOLOR="white"><H1>jspSmartUpload : Sample 1</H1>
<HR><FORM METHOD="POST" ACTION="/jspsmartupload/jsp/sample1.jsp" ENCTYPE="multipart/form-data">
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM></BODY>
</HTML>
JSP程序
sample1.jsp<%@ page language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" /><HTML>
<BODY BGCOLOR="white">
<H1>jspSmartUpload : Sample 1</H1>
<HR><% // Variables
int count=0; // Initialization
mySmartUpload.initialize(pageContext); mySmartUpload.setTotalMaxFileSize(100000); // Upload
mySmartUpload.upload(); try { // Save the files with their original names in the virtual path "/upload"
// if it doesn't exist try to save in the physical path "/upload"
count = mySmartUpload.save("/upload");
// Save the files with their original names in the virtual path "/upload"
// count = mySmartUpload.save("/upload", mySmartUpload.SAVE_VIRTUAL); // Display the number of files uploaded
out.println(count + " file(s) uploaded."); } catch (Exception e) {
out.println(e.toString());
}
%></BODY>
</HTML>
其实,只要你下载SMARTUPLOAD,它有好多例子。
当然,你也可以直接在
http://www.jspsmart.com/liblocal/download/EN/jspSmartUpload.zip
下载