【问题标题】:404 error when submitting form to servlet [duplicate]将表单提交到 servlet 时出现 404 错误 [重复]
【发布时间】:2018-09-06 05:38:17
【问题描述】:

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

索引.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 {

}

这是文件夹结构:

提前谢谢你!

【问题讨论】:

  • 您的Servlet 可以访问吗?

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


【解决方案1】:

我建议你在标签的“action”属性中提供“Context-path”。

在您的情况下,形成 action="faszkivan/servlets/HomeServlet"

form action="${pageContext.request.contextPath}/HomeServlet"

【讨论】:

    猜你喜欢
    • 2018-02-03
    • 2016-10-25
    • 2017-08-24
    • 2014-06-06
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 1970-01-01
    • 2021-08-29
    相关资源
    最近更新 更多