0

I'm trying to send a file with Servlet 3.0/JSP (IDE : Eclipse)

Here my JSP code :

<form method="post" action="UploadServlet"
    enctype="multipart/form-data">
    Select file to upload: <input type="file" name="file" size="60" /><br />
    <br /> <input type="submit" value="Upload" />
</form>

And my Servlet :

@WebServlet
@MultipartConfig(fileSizeThreshold = 1024 * 1024 * 2,
maxFileSize = 1024 * 1024 * 10,
maxRequestSize = 1024 * 1024 * 50)
public class UploadServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

private static final String SAVE_DIR = "uploadFiles";

protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException{


    //CODE

}

But when i submit my form, i got an error HTTP 404 The requested resource is not available.

Why ?

Apaachee
  • 900
  • 2
  • 10
  • 32
  • Where is the path for your servlet defined? Did you try `@WebServlet("/UploadServlet")`? – Uooo Mar 20 '13 at 12:21
  • Yes I tried and ot doesn't work. When i submit a normal form like
    it works on the servlet : @WebServlet("/Sauvegarde") public class Sauvegarde extends HttpServlet
    – Apaachee Mar 20 '13 at 12:30
  • To simplify : I have two classes @WebServlet("/UploadServlet") public class UploadServlet extends HttpServlet and @WebServlet("/Sauvegarde") public class Sauvegarde extends HttpServlet

    doesnt work but

    works
    – Apaachee Mar 20 '13 at 12:37

1 Answers1

0

you need to specify urlPatterns like

@WebServlet(name = "name", urlPatterns = {"/pattern"})

see here for example

PSR
  • 39,804
  • 41
  • 111
  • 151