HTTP 404 Servlet

时间:2013-03-20 12:17:44

标签: servlets file-upload http-status-code-404

我正在尝试使用Servlet 3.0 / JSP(IDE:Eclipse)发送文件

这是我的JSP代码:

<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>

我的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

}

但是当我提交表单时,我收到错误HTTP 404请求的资源不可用。

为什么?

1 个答案:

答案 0 :(得分:0)

你需要指定像

这样的urlPatterns
@WebServlet(name = "name", urlPatterns = {"/pattern"})
例如

see here