将表单提交给servlet

时间:2018-03-27 17:36:54

标签: java html jsp servlets http-status-code-404

我尝试使用servlet和JSP启动我的新项目,但我在第一步就陷入了困境。我无法使用servlet从一个html转发到另一个html。可能是什么问题?

的index.html:

<body>

    <form action="/servlets/HomeServlet" method="get">
        <label>Username</label> <input type="text" name="username" id="username"><br /> 
        <label>Password</label> <input type="password" name="password" id="password"><br /> 
        <input  type="submit" value="Submit">
    </form>

</body>

</html>

Sevlet:

public HomeServlet() {
    super();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/html/home.html").forwad(request,response);
}


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

}

这是文件夹结构:

https://i.imgur.com/PC0effY.jpg

提前谢谢!

1 个答案:

答案 0 :(得分:0)

我建议你提供&#34;上下文路径&#34;在你的&#34;行动&#34;标签的属性。

在您的情况下,表单操作=&#34; faszkivan / servlets / HomeServlet&#34;

form action =&#34; $ {pageContext.request.contextPath} / HomeServlet&#34;