title: Java servlets resource not found
body: <p>I am trying to enter a new user into my database with servlets.
  I have a problem when I click submit button i registraion form. I get "The requested resource is not available." error. I cant figure it out.</p>
  
  <p>Can you guys help me?</p>
  
  <p><strong>register.jsp</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
      &lt;title&gt;Sign Up&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h1&gt;Enter your information&lt;/h1&gt;
      &lt;form method = "POST" action="RegisterServlet"&gt;
          Username &lt;br/&gt;
          &lt;input type="text" name="username"/&gt;&lt;br/&gt;
          Password &lt;br/&gt;
          &lt;input type="password" name="password"/&gt;&lt;br/&gt;
          Email &lt;br/&gt;
          &lt;input type="text" name="email"/&gt;&lt;br/&gt;
          First name &lt;br/&gt;
          &lt;input type="text" name="fname"/&gt;&lt;br/&gt;
          Last name &lt;br/&gt;
          &lt;input type="text" name="lname"/&gt;&lt;br/&gt;
          &lt;input type="submit" value="Confirm" /&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>RegisterServlet doPost() method</strong></p>
  
  <pre><code>    package servlet;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.*;
  import javax.servlet.ServletException;
  import javax.servlet.annotation.WebServlet;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  @WebServlet(name = "RegisterServlet", urlPatterns = {"/RegisterServlet"})
  public class RegisterServlet extends HttpServlet {
  
      /**
       * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt;
       * methods.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
  
      }
  
      // &lt;editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."&gt;
      /**
       * Handles the HTTP &lt;code&gt;GET&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
      }
  
      /**
       * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          response.setContentType("text/html;charset=UTF-8");
          PrintWriter out = response.getWriter();
  
          String username = request.getParameter("username");
          String password = request.getParameter("password");
          String email = request.getParameter("email");
          String fname = request.getParameter("fname");
          String lname = request.getParameter("lname");
          String admin = "no";
  
          try {
              Class.forName("com.mysql.jdbc.Driver").newInstance();
              Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mobmelbaza", "root", "");
  
              String query = "insert into korisnici(user, pass, email, ime, prezime, admin)"
                      + "values ('" + username + "','" + password + "','" + email + "','" + fname + "','" + lname + "', '" + admin + "')";
  
              Statement st = con.createStatement();
  
              boolean done = st.execute(query);
  
              if (done == true) {
                  out.print("Sign Up sucessfull");
              } else {
                  out.print("Failed");
              }
  
          } catch (Exception ex) {
              ex.printStackTrace();
          }
  
      }
  
      /**
       * Returns a short description of the servlet.
       *
       * @return a String containing servlet description
       */
      @Override
      public String getServletInfo() {
          return "Short description";
      }// &lt;/editor-fold&gt;
  
  }
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;RegisterServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;servlet.RegisterServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;RegisterServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/RegisterServlet&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
  &lt;/web-app&gt;
  </code></pre>