dimanche 4 novembre 2018

tomcat says http method post is not supported by this url

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.




Aucun commentaire:

Enregistrer un commentaire