⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servletupload.java

📁 本程序的功能如下: 1)本程序完全采用jsp脚本技术 2)后台管理
💻 JAVA
字号:
package org.xg.upload ;
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 ServletUpload extends HttpServlet
{

    private ServletConfig config;

    /**
     * Init the servlet
     */
    final public void init(ServletConfig config) throws ServletException
    {
        this.config = config;
    }

    final public ServletConfig getServletConfig()
    {
        return config;
    }

    /**
     * Handles GET requests
     */
    public 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><BR>");
        out.println("The method of the HTML form must be POST.");
        out.println("</BODY>");
        out.println("</HTML>");
    }

    /**
     * Handles POST requests
     */
    protected void doPost(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>");

        // Variables
        int count = 0;
        SmartUpload mySmartUpload = new SmartUpload();

        try
        {
            // Initialization
            mySmartUpload.initialize(config,request,response);

            // Upload
            mySmartUpload.upload();

            // Save the file with the original name
            // in a virtual path of the web server
            count = mySmartUpload.save(mySmartUpload.getRequest().getParameter("PATH"));

            // Display the result
            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>");
    }

    /**
     * Destroy the servlet
     */
    public void destroy()
    {
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -