Administrator
2022-09-14 58d006e05dcf2a20d0ec5367dd03d66a61db6849
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package com.mandi.servlet;
 
import java.io.File;
import java.io.IOException;
import java.util.List;
 
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
 
import com.mandi.servlet.file.FileLoad;
import com.mandi.servlet.file.impl.FileLoadImpl;
import com.mandi.common.Jacksonmethod;
 
@WebServlet(name="fileuploadservlet",urlPatterns="/fileuploadservlet.sv")
public class Fileuploadservlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
 
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        this.doPost(req, resp);
    }
 
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        ApplicationContext a=WebApplicationContextUtils.getWebApplicationContext(req.getServletContext());
        if(a==null)
            return;
        String path1=req.getParameter("path");
        System.out.println(path1);
        if(path1==null||path1.isEmpty())
            path1="/temp";
            
        String    path=req.getServletContext().getRealPath(path1);
        File dir=new File(path);
        if(!dir.exists()||!dir.isDirectory())
            dir.mkdirs();
        FileLoad fl=a.getBean(FileLoadImpl.class);
        //String filepath=fl.uploadFile("/temp", req, true);
        List<Object> ls=fl.uploadFile_map(path1, req, true);
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("application/json; charset=utf-8");
        //resp.setContentType("text/html");  
        if(!ls.isEmpty())
            resp.getWriter().write(Jacksonmethod.tojson(ls.get(0), false));
    }    
}