servletUpload.java
上传用户:sxwtmm
上传日期:2022-08-11
资源大小:2183k
文件大小:2k
源码类别:

OA系统

开发平台:

Java

  1. import java.io.*;
  2. import java.util.*;
  3. import javax.servlet.*;
  4. import javax.servlet.http.*;
  5. import com.jspsmart.upload.*;
  6. public class servletUpload extends HttpServlet {
  7. private ServletConfig config;
  8. /**
  9. * Init the servlet
  10. */
  11. final public void init(ServletConfig config) throws ServletException {
  12. this.config = config;
  13. }
  14. final public ServletConfig getServletConfig() {
  15. return config;
  16. }
  17. /**
  18. * Handles GET requests
  19. */
  20. public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  21. PrintWriter out = response.getWriter();
  22. out.println("<HTML>");
  23. out.println("<BODY BGCOLOR='white'>");
  24. out.println("<H1>jspSmartUpload : Servlet Sample</H1>");
  25. out.println("<HR><BR>");
  26. out.println("The method of the HTML form must be POST.");
  27. out.println("</BODY>");
  28. out.println("</HTML>");
  29. }
  30. /**
  31. * Handles POST requests
  32. */
  33. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  34. PrintWriter out = response.getWriter();
  35. out.println("<HTML>");
  36. out.println("<BODY BGCOLOR='white'>");
  37. out.println("<H1>jspSmartUpload : Servlet Sample</H1>");
  38. out.println("<HR>");
  39. // Variables
  40. int count=0;
  41. SmartUpload mySmartUpload = new SmartUpload();
  42. try {
  43. // Initialization
  44. mySmartUpload.initialize(config,request,response);
  45. // Upload
  46. mySmartUpload.upload();
  47. // Save the file with the original name
  48. // in a virtual path of the web server
  49. count = mySmartUpload.save(mySmartUpload.getRequest().getParameter("PATH"));
  50. // Display the result
  51. out.println(count + " file uploaded.");
  52. } catch (Exception e){
  53. out.println("Unable to upload the file.<br>");
  54. out.println("Error : " + e.toString());
  55. }
  56. out.println("</BODY>");
  57. out.println("</HTML>");
  58.           }
  59. /**
  60. * Destroy the servlet
  61. */
  62. public void  destroy () {
  63. }