0
我正在使用@MultipartConfig
將文件上傳到數據庫,但它僅適用於小於5 MB的小文件。如何提高我的代碼以處理較大的文件?Servlet多部分配置無法上傳較大的文件
@WebServlet(name = "Upload", urlPatterns = {"/upload"})
@MultipartConfig(maxFileSize = 16177215)
public class Upload extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
InputStream in = null;
Part filePart = request.getPart("pdffile");
if (filePart != null) {
in = filePart.getInputStream();
}
Connection con = (Connection) getServletContext().getAttribute("Connection");
String sql = "INSERT INTO storepdf (pdffile) VALUES (?)";
try (PreparedStatement stat = con.prepareStatement(sql)) {
if (in != null) {
stat.setBlob(1, in);
}
int i = stat.executeUpdate();
request.setAttribute("res", i);
} catch (SQLException e) {
}
request.getRequestDispatcher("finish.jsp").forward(request, response);
}
}
我使用contextlistener初始化我與數據庫的連接和設置連接對象作爲一個上下文屬性的應用程序。 – Png