Fortunately, in my careful search finally found under the support of Chinese download jar upload
Package, with a jar package
The following are examples:
/ / index.jsp
<%@ page contentType="text/html;charset=GBK"%> <html> <head> <title>File Upload</title> </head> <body> <font size=5 color=#FF0000> <b>文件上传----使用jspsmart upload组件</b> </font> <br> <form action="uploadfile" method="post" enctype="multipart/form-data"> <p> 文件名称: <input type="file" name="file1" size="20" maxlength="80"> </p> <p> 文件名称: <input type="file" name="file2" size="20" maxlength="80"> </p> <p> 文件名称: <input type="file" name="file3" size="20" maxlength="80"> </p> <p> 上传路径: <input type="text" name="path" size="30" maxlength="50"> <br> </p> <p> 附加内容: <input type="text" name="other" size="30" maxlength="50"> </p> <p> <input type="submit" value="上传"> <input type="reset" value="重置"> </p> </form> <font size=5 color=#FF0000> <b>文件下载----使用jspsmart upload组件</b> </font> <br> <form action="downloadfile" method="post"> <p> 下载文件的名称: <input type="text" name="downloadFileName" size="20" maxlength="80"> </p> <input type="submit" value="下载"> </body> </form> </html>
==================================================
/ / Servlet: ServletUpload.java Upload
package wit.ou;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.SmartUpload;
/**
* 描述:上传servlet
* @author 2009-3-4 转载 http://www.blogjava.net/hijackwust/archive/2007/08/22/138598.html
*
*/
public class ServletUpload extends HttpServlet {
private ServletConfig config;
final public void init(ServletConfig config) throws ServletException {
this.config = config;
}
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<BODY BGCOLOR='white'>");
out.println("<H1>jspSmartUpload : Servlet Sample</H1>");
out.println("<HR>");
// 变量定义
int count = 0;
//创建一个SmartUpload类
SmartUpload mySmartUpload = new SmartUpload();
try {
//初始化
mySmartUpload.initialize(config, request, response);
//上传
mySmartUpload.upload();
for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
com.jspsmart.upload.File myfile = mySmartUpload.getFiles().getFile(i);
String fileName = myfile.getFileName();
//保存
count = mySmartUpload.save("/upload");
//count = mySmartUpload.save(null);
}
out.println(count + " file uploaded.");
} catch (Exception e) {
out.println("Unable to upload the file.<br>");
out.println("Error : " + e.toString());
}
//通过 方法 mySmartUpload.getRequest().getParameter(arg0);还可以获取传过来的非file类型的其他值。
out.println("</BODY>");
out.println("</HTML>");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
/ / servlet: ServletDownload.java download
package wit.ou;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.SmartUpload;
public class ServletDownload extends HttpServlet {
private ServletConfig config;
final public void init(ServletConfig config) throws ServletException {
this.config = config;
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String temp_p =request.getParameter("downloadFileName");
byte[] temp_t=temp_p.getBytes("ISO8859_1");
String fileName=new String(temp_t,"GBK");
SmartUpload mySmartUpload = new SmartUpload();
try {
//初始化
mySmartUpload.initialize(config, request, response);
//设置不自动打开
mySmartUpload.setContentDisposition(null);
mySmartUpload.downloadFile("/upload/"+fileName);
} catch (Exception e) {
e.printStackTrace();
}
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
From one of the time can also provide ways to package jar set up some parameters to upload!
Download file commonly used method
1, setContentDisposition
Role: additional data to the MIME header of the CONTENT-DISPOSITION domain. jspSmartUpload component will download the information back automatically fill in MIME header of the CONTENT-DISPOSITION domain, if the user need to add additional information, please use this method.
Prototype: public void setContentDisposition (String contentDisposition)
One of, contentDisposition order to add data. If contentDisposition for the null, the component will automatically add "attachment;", to indicate that the document will download as an attachment, the result is the IE browser will be prompted to save a document, rather than automatically open the document (IE browser in general accordance with download file extensions What do decide to implement the extension of the doc will be used to open word, pdf extension will open with acrobat, etc.).
2, downloadFile
Role: to download the file.
Prototype: A total of three prototypes are available, the first one of the most commonly used, the latter two used in exceptional circumstances, download the document (such as changing the content type, change the Save as file name).
① public void downloadFile (String sourceFilePathName)
One of, sourceFilePathName In order to download the file name (with full name of the file directory)
② public void downloadFile (String sourceFilePathName, String contentType)
One of, sourceFilePathName In order to download the file name (with full name of the directory file), contentType for the content type (MIME format of the file type information, may be the browser identification).
③ public void downloadFile (String sourceFilePathName, String contentType, String destFileName)
One of, sourceFilePathName In order to download the file name (with full name of the directory file), contentType for the content type (MIME format of the file type information, may be the browser identification), destFileName for download after the default save file name.
On here, and after what has become one after another to add up







