楼主可以把你的smartupload 发给我吗?
[email protected]
谢谢

解决方案 »

  1.   

    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import com.jspsmart.upload.*;public class servletUpload extends HttpServlet {
      private static final String CONTENT_TYPE = "text/html; charset=GBK";
      private ServletConfig config;
      //Initialize global variables
      public void init(ServletConfig config) throws ServletException {
        this.config=config;
      }  //Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        out.println("<html>");
        out.println("<head><title>servletUpload</title></head>");
        out.println("<body bgcolor=\"#ffffff\">");
        out.println("<H1>jspSmartUpload:Servlet Sample</H1>");
        out.println("<HR><BR>");
        out.println("The method of the HTML form must be POST.");
        out.println("</body></html>");
      }  //Process the HTTP Post request
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.println("<HTML>");
        out.println("<BODY bgcolor=\"#ffffff\">");
        out.println("<h1>jspSmartUpload:Servlet Sample</h1>");
        out.println("<HR>");
        //变量定义
        int count=0;
        SmartUpload mySmartUpload=new SmartUpload();
        try{
          //初始化
          mySmartUpload.initialize(config,request,response);
          //上载
          mySmartUpload.upload();
          //保存上载文件到指定目录,PATH为form表单提交过来的
          count=mySmartUpload.save(mySmartUpload.getRequest().getParameter("PATH"));
          //显示处理结果
          out.println(count+" file uploaded.");
        }catch(Exception e){
          out.println("Unable to upload the file.<br>");
          out.println("Error:"+e.toString());
        }
        out.println("</BODY>");
        out.println("</html>");
      }  //Clean up resources
      public void destroy() {
      }
    }<%@ page contentType="text/html; charset=GBK" %>
    <html>
    <head>
    <title>
    file upload
    </title>
    </head>
    <body bgcolor="#ffffff">
    <font size="5" color="#FF0000">
      <b>文件上传-使用jspmart upload组件
      </b>
    </font><br />
    <!--enctype属性的值必须为multipart/form-data,method属性的值必须为post,否则不能实现上传功能-->
    <form name="selectfile" enctype="multipart/form-data" method="POST" action="/myweb/servletupload">
      <p>文件名称:
        <input type="file" name="ulfile" size="20" maxlength="80" />
      </p>
      <p>存储路径:
        <input  type="text" name="PATH" size="30" maxlength="50"/>
      </p>
      <p>
        <select name="aa" size=10/>
      </p>
      <p>
      <input type="submit" value="上传" />
      <input  type="reset" value="清除"/>
      </p>
    </form>
    </body>
    </html>