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