在jsp文件中单击提交时,不会调用doPost方法

时间:2018-02-04 14:17:07

标签: java xml jsp servlets web-applications

我正在关注此链接中的教程。https://www.youtube.com/watch?v=pOUDEFVjUXM。我没有使用任何IDE。我正在配置library(gsubfn) fn$Filter(~ all(2:3 %in% x), L) 文件,而不是使用注释。我正在使用Tomcat。我正在使用的文件如下。

LoginServlet.java

web.xml

的web.xml

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import javax.servlet.ServletException;
import java.io.PrintWriter;

public class LoginServlet extends HttpServlet
{
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    request.getRequestDispatcher("login.jsp").forward(request,response);
  }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  {
    response.getWriter().println("Success");
  }
}

的login.jsp

<web-app>
  <servlet>
    <servlet-name>loginservlet</servlet-name>
    <servlet-class>LoginServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>loginservlet</servlet-name>
    <url-pattern>/login</url-pattern>
  </servlet-mapping>
</web-app>

当我在login.jsp页面输入用户名和密码时,我收到the following error in Tomcat

  

HTTP状态404
  类型:状态报告
  消息:登录
  描述:原始服务器没有找到目标资源的当前表示,或者不愿意透露htat存在。

但在本教程中,调用了doPost方法。我被卡住了。请帮忙。

1 个答案:

答案 0 :(得分:0)

我想您错过了将您的网址添加到您的contextPath。 在tomcat中,contextPath与项目名称一致。

替换您的login.jsp action="/[myProjectName]/login"