Servlet for upload.jsp

This commit is contained in:
Thoughtscript 2018-05-14 10:51:17 +01:00
parent 368fb608f7
commit 19dd1a83ae
4 changed files with 28 additions and 24 deletions

View File

@ -4,6 +4,7 @@ import com.baeldung.Constants;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -14,6 +15,10 @@ import java.io.IOException;
import static com.baeldung.Constants.UPLOAD_DIRECTORY;
@WebServlet(
name = "MultiPartServlet",
urlPatterns = {"/multiPartServlet"}
)
@MultipartConfig(fileSizeThreshold = 1024 * 1024, maxFileSize = 1024 * 1024 * 5, maxRequestSize = 1024 * 1024 * 5 * 5)
public class MultipartServlet extends HttpServlet {

View File

@ -1,5 +1,6 @@
package com.baeldung.servlets;
import javax.servlet.annotation.WebServlet;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
@ -14,6 +15,10 @@ import java.util.List;
import static com.baeldung.Constants.*;
@WebServlet(
name = "UploadServlet",
urlPatterns = {"/uploadFile"}
)
public class UploadServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

View File

@ -0,0 +1,18 @@
package com.baeldung.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet(name = "UploadWelcomeServlet", urlPatterns = "/uploadwelcome")
public class UploadWelcomeServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher("/upload.jsp").forward(request, response);
}
}

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>com.baeldung.servlets.UploadServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/uploadFile</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>MultiPartServlet</servlet-name>
<servlet-class>com.baeldung.servlets.MultipartServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MultiPartServlet</servlet-name>
<url-pattern>/multiPartServlet</url-pattern>
</servlet-mapping>
</web-app>