HTTP状态404 - / ShowForm

时间:2017-10-25 10:48:07

标签: java

我收到HTTP状态404 - / ShowForm这个错误请帮我解决这个问题。

ShowForm.html

<form action = "/ShowForm" method = "post" enctype="multipart/form-data" >
Name: <input type = "text" name = "name" /><br>
File: <input type = "file" name = "file" /><br>
  <input type = "submit" value = "submit" name = "submit">
</form>

ShowForm.java

@WebServlet("/ShowForm")
public class ShowForm extends HttpServlet {
    private static final long serialVersionUID = 1L;


    public ShowForm() {
        super();
        // TODO Auto-generated constructor stub
    }
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        //response.getWriter().append("Served at: ").append(request.getContextPath());
        response.setContentType("text/plain");
        PrintWriter pw = response.getWriter();
        ServletInputStream sis = request.getInputStream();
        for(int i = sis.read();i != -1;i = sis.read())
        {
            pw.print((char)i);
        }
    }
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }
}

这里我使用的是Annotation,因此我没有在web.xml中进行映射。

0 个答案:

没有答案