//下载
<%@ page import="java.io.*;"%>
<%
try {

String url = "D:/websrc/aaa.doc";// 实际文件路径 
String name = "默认中文文件名.doc";//显示给用户看的文件名,即ie弹出下载框中提示保存的文件名
//response.reset();
response.setContentType("bin");
response.setHeader("Content-Disposition", "attachment; filename="+name);//处理默认文件名的中文问题 ServletOutputStream os = response.getOutputStream();
FileInputStream in = new FileInputStream(url);
byte[] data = new byte[1024];
int temp = -1;
while((temp=in.read(data))!= -1){
os.write(data,0,temp);
os.flush();
}//while//
in.close();
os.close();
} catch(Exception e) {
out.print(e.toString());
}
%>

解决方案 »

  1.   

    //上存
    /*  upload.html */
    <HTML>
    <HEAD></HEAD><BODY>
    <form name="form1" method="post" enctype="multipart/form-data" action="upload.jsp" >
    <input type="file" name="file" class="textbox" size="30">
    <input type=submit name=submit value="submit"></form>
    </BODY>
    </HTML>/* upload.jsp */
    <%@ page contentType="text/html; charset=gb2312" buffer="1" autoFlush="true"%><%@ page import="com.jspsmart.upload.*" %>
    <%@ page import="java.util.*" %>
    <%@ page import="java.text.*" %>
    <body><%
    try{
    SmartUpload upload = new SmartUpload();
    upload.initialize(pageContext);
    upload.upload();
    for (int i=0;i<upload.getFiles().getCount();i++){
    com.jspsmart.upload.File newFile = upload.getFiles().getFile(i);
    if (!newFile.isMissing()) {
    newFile.saveAs("d:/websrc/upload/newFileName" );//修改你的存储路径
    out.println("FieldName = " + newFile.getFieldName() + "<BR>");
    out.println("Size = " + newFile.getSize() + "<BR>");
    out.println("FileName = " + newFile.getFileName() + "<BR>");
    out.println("FileExt = " + newFile.getFileExt() + "<BR>");
    out.println("FilePathName = " + newFile.getFilePathName() + "<BR>");
    out.println("ContentType = " + newFile.getContentType() + "<BR>");
    out.println("ContentDisp = " + newFile.getContentDisp() + "<BR>");
    out.println("TypeMIME = " + newFile.getTypeMIME() + "<BR>");
    out.println("SubTypeMIME = " + newFile.getSubTypeMIME() + "<BR>"); } }
    }catch(Exception e){
    out.println(e.toString());
    }
    %>
    </body>