tomcat says http method post is not supported by this url











up vote
0
down vote

favorite












i've been calling servlet by a HTML page and my servlet code goes like this:



import java.sql.*;
import javax.servlet.http.*;
import java.io.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;

public class validation extends HttpServlet
{
static PrintWriter pw = null;
public void doPost(HttpServletResponse response, HttpServletRequest request) throws ClassNotFoundException, SQLException, IOException, ServletException
{
pw = response.getWriter();
String username = request.getParameter("username");
String password = request.getParameter("password");
RequestDispatcher rd = request.getRequestDispatcher("new.html");
Class.forName("java.sql.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/timetabledb", "root","`");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select password from users where username = '"+username+"';");
if(rs.next()==false)
{
pw.println("No such user found!");
}
else
{
if(password.equals(rs.getString("password")))
{
rd.forward(request, response);
}
else
{
pw.println("Invalid credentials!");
}
}
rs.close();
}
}


and my html page is this:



<!DOCTYPE html>
<html>
<head>
<title>Login Page - SGMS</title>
<link rel="stylesheet" href="main.css" />
</head>

<body>
<div id = "container">
<div class = "welcome-head">
Welcome
</div>
<div class = "sw-head">
Semi-Automatic Schedule Generator & Maintenance Software
</div>
<span class="logo">
<img src="logo.gif" alt="Logo"/>
</span>
<div class = "form">
<form method="POST" action="validation">
<label for="inp-usr" class="inp">
<input type="text" name="username" id="inp-usr" placeholder="&nbsp;" required="required">
<span class="label">Username</span>
<span class="border"></span>
</label>
<br>
<label for="inp-pwd" class="inp">
<input type="password" name="password" id="inp-pwd" placeholder="&nbsp;" required="required">
<span class="label">Password</span>
<span class="border"></span>
</label>
<br><br><br>
<button class="validate-btn" onclick="show();">
Validate
</button>
</form>
</div>
</div>
</body>

</html>


but the problem is that whenever i run all this, the application server says, that POST method isn't supported by this url.
I've experienced this error frequently, please explain why all this happens.
I've mapped the servlet in my web.xml



Thanks in advance.










share|improve this question


























    up vote
    0
    down vote

    favorite












    i've been calling servlet by a HTML page and my servlet code goes like this:



    import java.sql.*;
    import javax.servlet.http.*;
    import java.io.*;
    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;

    public class validation extends HttpServlet
    {
    static PrintWriter pw = null;
    public void doPost(HttpServletResponse response, HttpServletRequest request) throws ClassNotFoundException, SQLException, IOException, ServletException
    {
    pw = response.getWriter();
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    RequestDispatcher rd = request.getRequestDispatcher("new.html");
    Class.forName("java.sql.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/timetabledb", "root","`");
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery("select password from users where username = '"+username+"';");
    if(rs.next()==false)
    {
    pw.println("No such user found!");
    }
    else
    {
    if(password.equals(rs.getString("password")))
    {
    rd.forward(request, response);
    }
    else
    {
    pw.println("Invalid credentials!");
    }
    }
    rs.close();
    }
    }


    and my html page is this:



    <!DOCTYPE html>
    <html>
    <head>
    <title>Login Page - SGMS</title>
    <link rel="stylesheet" href="main.css" />
    </head>

    <body>
    <div id = "container">
    <div class = "welcome-head">
    Welcome
    </div>
    <div class = "sw-head">
    Semi-Automatic Schedule Generator & Maintenance Software
    </div>
    <span class="logo">
    <img src="logo.gif" alt="Logo"/>
    </span>
    <div class = "form">
    <form method="POST" action="validation">
    <label for="inp-usr" class="inp">
    <input type="text" name="username" id="inp-usr" placeholder="&nbsp;" required="required">
    <span class="label">Username</span>
    <span class="border"></span>
    </label>
    <br>
    <label for="inp-pwd" class="inp">
    <input type="password" name="password" id="inp-pwd" placeholder="&nbsp;" required="required">
    <span class="label">Password</span>
    <span class="border"></span>
    </label>
    <br><br><br>
    <button class="validate-btn" onclick="show();">
    Validate
    </button>
    </form>
    </div>
    </div>
    </body>

    </html>


    but the problem is that whenever i run all this, the application server says, that POST method isn't supported by this url.
    I've experienced this error frequently, please explain why all this happens.
    I've mapped the servlet in my web.xml



    Thanks in advance.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      i've been calling servlet by a HTML page and my servlet code goes like this:



      import java.sql.*;
      import javax.servlet.http.*;
      import java.io.*;
      import javax.servlet.RequestDispatcher;
      import javax.servlet.ServletException;

      public class validation extends HttpServlet
      {
      static PrintWriter pw = null;
      public void doPost(HttpServletResponse response, HttpServletRequest request) throws ClassNotFoundException, SQLException, IOException, ServletException
      {
      pw = response.getWriter();
      String username = request.getParameter("username");
      String password = request.getParameter("password");
      RequestDispatcher rd = request.getRequestDispatcher("new.html");
      Class.forName("java.sql.Driver");
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/timetabledb", "root","`");
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery("select password from users where username = '"+username+"';");
      if(rs.next()==false)
      {
      pw.println("No such user found!");
      }
      else
      {
      if(password.equals(rs.getString("password")))
      {
      rd.forward(request, response);
      }
      else
      {
      pw.println("Invalid credentials!");
      }
      }
      rs.close();
      }
      }


      and my html page is this:



      <!DOCTYPE html>
      <html>
      <head>
      <title>Login Page - SGMS</title>
      <link rel="stylesheet" href="main.css" />
      </head>

      <body>
      <div id = "container">
      <div class = "welcome-head">
      Welcome
      </div>
      <div class = "sw-head">
      Semi-Automatic Schedule Generator & Maintenance Software
      </div>
      <span class="logo">
      <img src="logo.gif" alt="Logo"/>
      </span>
      <div class = "form">
      <form method="POST" action="validation">
      <label for="inp-usr" class="inp">
      <input type="text" name="username" id="inp-usr" placeholder="&nbsp;" required="required">
      <span class="label">Username</span>
      <span class="border"></span>
      </label>
      <br>
      <label for="inp-pwd" class="inp">
      <input type="password" name="password" id="inp-pwd" placeholder="&nbsp;" required="required">
      <span class="label">Password</span>
      <span class="border"></span>
      </label>
      <br><br><br>
      <button class="validate-btn" onclick="show();">
      Validate
      </button>
      </form>
      </div>
      </div>
      </body>

      </html>


      but the problem is that whenever i run all this, the application server says, that POST method isn't supported by this url.
      I've experienced this error frequently, please explain why all this happens.
      I've mapped the servlet in my web.xml



      Thanks in advance.










      share|improve this question













      i've been calling servlet by a HTML page and my servlet code goes like this:



      import java.sql.*;
      import javax.servlet.http.*;
      import java.io.*;
      import javax.servlet.RequestDispatcher;
      import javax.servlet.ServletException;

      public class validation extends HttpServlet
      {
      static PrintWriter pw = null;
      public void doPost(HttpServletResponse response, HttpServletRequest request) throws ClassNotFoundException, SQLException, IOException, ServletException
      {
      pw = response.getWriter();
      String username = request.getParameter("username");
      String password = request.getParameter("password");
      RequestDispatcher rd = request.getRequestDispatcher("new.html");
      Class.forName("java.sql.Driver");
      Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/timetabledb", "root","`");
      Statement stmt = con.createStatement();
      ResultSet rs = stmt.executeQuery("select password from users where username = '"+username+"';");
      if(rs.next()==false)
      {
      pw.println("No such user found!");
      }
      else
      {
      if(password.equals(rs.getString("password")))
      {
      rd.forward(request, response);
      }
      else
      {
      pw.println("Invalid credentials!");
      }
      }
      rs.close();
      }
      }


      and my html page is this:



      <!DOCTYPE html>
      <html>
      <head>
      <title>Login Page - SGMS</title>
      <link rel="stylesheet" href="main.css" />
      </head>

      <body>
      <div id = "container">
      <div class = "welcome-head">
      Welcome
      </div>
      <div class = "sw-head">
      Semi-Automatic Schedule Generator & Maintenance Software
      </div>
      <span class="logo">
      <img src="logo.gif" alt="Logo"/>
      </span>
      <div class = "form">
      <form method="POST" action="validation">
      <label for="inp-usr" class="inp">
      <input type="text" name="username" id="inp-usr" placeholder="&nbsp;" required="required">
      <span class="label">Username</span>
      <span class="border"></span>
      </label>
      <br>
      <label for="inp-pwd" class="inp">
      <input type="password" name="password" id="inp-pwd" placeholder="&nbsp;" required="required">
      <span class="label">Password</span>
      <span class="border"></span>
      </label>
      <br><br><br>
      <button class="validate-btn" onclick="show();">
      Validate
      </button>
      </form>
      </div>
      </div>
      </body>

      </html>


      but the problem is that whenever i run all this, the application server says, that POST method isn't supported by this url.
      I've experienced this error frequently, please explain why all this happens.
      I've mapped the servlet in my web.xml



      Thanks in advance.







      java html tomcat web






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 4 at 9:51









      Gaurav Goswami

      13




      13
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote













          You have made a mistake in your doPost method. You have declared it as this:



          void doPost(HttpServletResponse response, HttpServletRequest request)
          throws ClassNotFoundException, SQLException, IOException, ServletException


          but the correct signature is this:



          void doPost(HttpServletRequest req, HttpServletResponse resp) 
          throws ServletException, IOException


          Notice the different parameter order ....



          Since your method doesn't have the correct signature, it is not overriding the inherited version. That means that your version never gets called. Instead, a POST requests calls the inherited method ... and the behavior of that is to say "POST not supported".



          Solution:




          1. Correct your doPost method's signature. (The exceptions will need fixing too!)

          2. Add an @Override annotation to this ... and any other override methods in this class.

          3. Get into the habit of always using @Override wherever you intend to override a method.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139540%2ftomcat-says-http-method-post-is-not-supported-by-this-url%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote













            You have made a mistake in your doPost method. You have declared it as this:



            void doPost(HttpServletResponse response, HttpServletRequest request)
            throws ClassNotFoundException, SQLException, IOException, ServletException


            but the correct signature is this:



            void doPost(HttpServletRequest req, HttpServletResponse resp) 
            throws ServletException, IOException


            Notice the different parameter order ....



            Since your method doesn't have the correct signature, it is not overriding the inherited version. That means that your version never gets called. Instead, a POST requests calls the inherited method ... and the behavior of that is to say "POST not supported".



            Solution:




            1. Correct your doPost method's signature. (The exceptions will need fixing too!)

            2. Add an @Override annotation to this ... and any other override methods in this class.

            3. Get into the habit of always using @Override wherever you intend to override a method.






            share|improve this answer

























              up vote
              1
              down vote













              You have made a mistake in your doPost method. You have declared it as this:



              void doPost(HttpServletResponse response, HttpServletRequest request)
              throws ClassNotFoundException, SQLException, IOException, ServletException


              but the correct signature is this:



              void doPost(HttpServletRequest req, HttpServletResponse resp) 
              throws ServletException, IOException


              Notice the different parameter order ....



              Since your method doesn't have the correct signature, it is not overriding the inherited version. That means that your version never gets called. Instead, a POST requests calls the inherited method ... and the behavior of that is to say "POST not supported".



              Solution:




              1. Correct your doPost method's signature. (The exceptions will need fixing too!)

              2. Add an @Override annotation to this ... and any other override methods in this class.

              3. Get into the habit of always using @Override wherever you intend to override a method.






              share|improve this answer























                up vote
                1
                down vote










                up vote
                1
                down vote









                You have made a mistake in your doPost method. You have declared it as this:



                void doPost(HttpServletResponse response, HttpServletRequest request)
                throws ClassNotFoundException, SQLException, IOException, ServletException


                but the correct signature is this:



                void doPost(HttpServletRequest req, HttpServletResponse resp) 
                throws ServletException, IOException


                Notice the different parameter order ....



                Since your method doesn't have the correct signature, it is not overriding the inherited version. That means that your version never gets called. Instead, a POST requests calls the inherited method ... and the behavior of that is to say "POST not supported".



                Solution:




                1. Correct your doPost method's signature. (The exceptions will need fixing too!)

                2. Add an @Override annotation to this ... and any other override methods in this class.

                3. Get into the habit of always using @Override wherever you intend to override a method.






                share|improve this answer












                You have made a mistake in your doPost method. You have declared it as this:



                void doPost(HttpServletResponse response, HttpServletRequest request)
                throws ClassNotFoundException, SQLException, IOException, ServletException


                but the correct signature is this:



                void doPost(HttpServletRequest req, HttpServletResponse resp) 
                throws ServletException, IOException


                Notice the different parameter order ....



                Since your method doesn't have the correct signature, it is not overriding the inherited version. That means that your version never gets called. Instead, a POST requests calls the inherited method ... and the behavior of that is to say "POST not supported".



                Solution:




                1. Correct your doPost method's signature. (The exceptions will need fixing too!)

                2. Add an @Override annotation to this ... and any other override methods in this class.

                3. Get into the habit of always using @Override wherever you intend to override a method.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 4 at 13:11









                Stephen C

                506k68552903




                506k68552903






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139540%2ftomcat-says-http-method-post-is-not-supported-by-this-url%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    這個網誌中的熱門文章

                    Xamarin.form Move up view when keyboard appear

                    Post-Redirect-Get with Spring WebFlux and Thymeleaf

                    Anylogic : not able to use stopDelay()