title: Http Status 404- Path is incorrect when connecting .jsp and servlet via <form action="servletname">
body: <p>I am having trouble after I hit submit on my login.jsp. I receive an error message stating:</p>
  
  <p>HTTP Status 404 - /LA/Controller</p>
  
  <p>type Status report</p>
  
  <p>message /LA/Controller</p>
  
  <p>description The requested resource is not available.</p>
  
  <p>Apache Tomcat/7.0.50</p>
  
  <ul>
  <li>I am using Eclipse Java EE and tomcat server. Any help/suggestions would be greatly appreciated. Thanks in advance!</li>
  </ul>
  
  <p>Cheers</p>
  
  <p>My directory is as follows in eclipse Java EE:</p>
  
  <pre><code>LA
    - Java Resources
    - src
    - p1
      - Controller.java
  WebContent
   - META-INF
   -VIEWS
       - .....
       - login.jsp
       - index.jsp
       - welcome.jsp
  - WEB-INF
        -lib
            jstl-1.2.jar
            mysql-connector-java...
        -web.xml
  </code></pre>
  
  <p>My servlet- Controller.java:</p>
  
  <pre><code>package p1;
  
  
  public class Controller extends HttpServlet {
  private static final long serialVersionUID = 1L;
  //  static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";  
  //  static final String DB_URL = "jdbc:mysql://localhost/jdb";  
  
  /**
   * @see HttpServlet#HttpServlet()
   */
  public Controller() {
  
      super();
      // TODO Auto-generated constructor stub
  }
  
  ///=============== 
   public static boolean validate(String name, String pass) {          
      boolean status = false;  
      Connection conn = null;  
      PreparedStatement pst = null;  
      ResultSet rs = null;  
  
      String url = "jdbc:mysql://localhost:3306/";  
      String dbName = "jdb";  
      String driver = "com.mysql.jdbc.Driver";  
      String userName = "root";  
      String password = "bluepanda1";  
      try {  
          Class.forName(driver).newInstance();  
          conn = DriverManager  
                  .getConnection(url + dbName, userName, password);  
  
          pst = conn  
                  .prepareStatement("select * from login where user=? and password=?");  
          pst.setString(1, name);  
          pst.setString(2, pass);  
  
          rs = pst.executeQuery();  
          status = rs.next();  
  
      } catch (Exception e) {  
          System.out.println(e);  
      } finally {  
          if (conn != null) {  
              try {  
                  conn.close();  
              } catch (SQLException e) {  
                  e.printStackTrace();  
              }  
          }  
          if (pst != null) {  
              try {  
                  pst.close();  
              } catch (SQLException e) {  
                  e.printStackTrace();  
              }  
          }  
          if (rs != null) {  
              try {  
                  rs.close();  
              } catch (SQLException e) {  
                  e.printStackTrace();  
              }  
          }  
      }  
      return status;  
  }  
  
  
  /**
  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  */
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws              
  
     ServletException, IOException {
  // TODO Auto-generated method stub
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      out.print("Test");
  
     }
  /**
   * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
   */
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws   
     ServletException, IOException {
      // TODO Auto-generated method stub
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
  
      String n=request.getParameter("username");
      String p=request.getParameter("password");
  
      HttpSession session = request.getSession(false);
      if(session!=null)
          session.setAttribute("name",n);
  
      if(Controller.validate(n, p)){
          RequestDispatcher rd = request.getRequestDispatcher("welcome.jsp");
          rd.forward(request, response);
      }
      else{
          out.print("&lt;p style=\"color:red\"&gt; Sorry username or password             
         error&lt;/p&gt;");
          RequestDispatcher rd = request.getRequestDispatcher("login.jsp");
          rd.include(request, response);
      }
      out.close();    
  }
  
   }
  </code></pre>
  
  <p>my login.jsp:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=US-ASCII"
  pageEncoding="US-ASCII"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"      
  "http://www.w3.org/TR/html4/loose.dtd"&gt;
   &lt;html&gt;
   &lt;head&gt;  
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;&lt;/title&gt;
  &lt;meta name="keywords" content="" /&gt;
  &lt;meta name="description" content="" /&gt;
  &lt;link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700,800"     
  rel="stylesheet" /&gt;
  &lt;link href="default.css" rel="stylesheet" type="text/css" media="all" /&gt;
  &lt;link href="fonts.css" rel="stylesheet" type="text/css" media="all" /&gt;
  &lt;c:url var="actionUrl" value="/Controller"/&gt; 
  
  
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="header-wrapper"&gt;
  &lt;div id="header" class="container"&gt;
      &lt;div id="logo"&gt;
          &lt;h1&gt;&lt;a href="#"&gt;The Legal Network&lt;/a&gt;&lt;/h1&gt;
      &lt;/div&gt;
      &lt;div id="menu"&gt;
          &lt;ul&gt;
              &lt;li&gt;&lt;a href="index.jsp"  accesskey="1" title=""&gt;Homepage&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="createAct.jsp" accesskey="2" title=""&gt;Create   
     Account&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="login.jsp" accesskey="3" title=""&gt;Login&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="logout.jsp" accesskey="4" title=""&gt;Logout&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="contact.jsp" accesskey="5" title=""&gt;Contact Us&lt;/a&gt;   
    &lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
  &lt;/div&gt;
    &lt;/div&gt;
    &lt;div id="featured"&gt;&amp;nbsp;&lt;/div&gt;
  &lt;div id="wrapper"&gt;
  &lt;div id="page" class="container"&gt;
      &lt;div id="content"&gt;
          &lt;div class="title"&gt;
              &lt;h2&gt;Log In&lt;/h2&gt;
              &lt;form action="Controller" method="post"&gt;
              &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;Username:&lt;/td&gt;
                  &lt;td&gt;&lt;input type="text" name="Username"&gt;&lt;/td&gt; 
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;Password:&lt;/td&gt;
                  &lt;td&gt;&lt;input type="password" name="Password"&gt;&lt;/td&gt; 
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;&lt;input type="submit" name="submit"&gt;&lt;/td&gt; 
              &lt;/tr&gt;
              &lt;/table&gt;
              &lt;/form&gt;
              &lt;/div&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;
    &lt;/div&gt;
    &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>
  
  <p>My web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
   xmlns="http://java.sun.com/xml/ns/javaee"    
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web- 
   app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
  &lt;servlet&gt;  
      &lt;servlet-name&gt;Controller&lt;/servlet-name&gt;  
      &lt;servlet-class&gt;p1.Controller&lt;/servlet-class&gt;  
  &lt;/servlet&gt;  
  
  &lt;servlet-mapping&gt;   
      &lt;servlet-name&gt;Controller&lt;/servlet-name&gt;  
      &lt;url-pattern&gt;Controller&lt;/url-pattern&gt;  
  &lt;/servlet-mapping&gt;  
  
  &lt;welcome-file-list&gt;
  &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
  &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
  &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
  &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
  &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
  &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
  &lt;welcome-file&gt;login.jsp&lt;/welcome-file&gt;
  &lt;welcome-file&gt;welcome.jsp&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>