0

When I run the html file, fill the data, get the blank page and run the servlet file "http status 405-get method is not allowed by this url" error occurs.

Also the class not found exception error is the main error in my code that occurs from starting. I'm been trying to solve this problem for the last 4-5 days but I couldn't find a solution.

Enter code here out from this problem.

I have added servlet-api.jar and mysql-connector-java- 8.0.12.jar files.

Please, solve my problem.

This is my index.html

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Login Page</title>
    </head>
    <body>
    <form method="post" action="/InsertServlet">
     Username: <input type="text" name="username"/><br/><br/>
     Password: <input type="password" name="password"/><br/><br/>

     <input type="submit" value="Submit"/>
     <input type="reset" value="Reset"/>
     </form>
     </body>
     </html>

This is my InsertServlet.java class

    package org.studyeasy.servlet;

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.*;


    public class InsertServlet extends HttpServlet {
        Connection con;
        Statement st;
        String user,pass;
     protected void doPost(HttpServletRequest request, 
     HttpServletResponse response) throws ServletException, IOException {
     response.setContentType("text/html;charset=UTF-8");

      try (PrintWriter out=response.getWriter()){
        user=request.getParameter("username");
        pass=request.getParameter("password");
        Class.forName("com.mysql.jdbc.Driver");
        con=DriverManager.getConnection
      ("jdbc:mysql://localhost/mydatabase","root","rohini2722");
        st=con.createStatement();

        String query="insert into Login values('"+user+"','"+pass+"')";
        st.executeUpdate(query);

        System.out.println("Data Inserted Successfully");

     }
     catch(Exception e){
     e.printStackTrace();
      }
     }
    }

This is my web.xml

     <?xml version="1.0" encoding="UTF-8"?>
        <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_2_5.xsd" id="WebApp_ID" 
        version="2.5">
        <display-name>Login Page</display-name>
       <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
      <servlet>
        <description></description>
        <display-name>InsertServlet</display-name>
        <servlet-name>InsertServlet</servlet-name>
        <servlet-class>org.studyeasy.servlet.InsertServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>InsertServlet</servlet-name>
        <url-pattern>/InsertServlet</url-pattern>
      </servlet-mapping>
    </web-app>
sao
  • 1,469
  • 6
  • 14
  • 30

0 Answers0