404 error while redirecting to html from a servlet












0














I have a problem with a school project, it's a little web dinamic project.
In the Login page, if I submit parameters of a user that exist in my DB, all goes well and I have my "success.html" page, but if I submit parameters of a user that is not in my DB I have a 404 page, while I'm expecting my "failure.html".
Could u please help me to find the error?



I'm using:




  • Eclipse Java Neon

  • Tomcat 9.0.12


This is my login form:



<form id="login" class="form-horizontal" action="/IROPLAS/Controller/LoginServlet" method="GET">
<div class="form-group">
<label class="control-label col-xs-8 col-sm-4 col-md-5" for="mail">E-mail:</label>
<div class="col-xs-10 col-sm-8 col-md-4">
<input type="text" class="form-control" id="mail" name="mail" placeholder="E-mail">
</div>
</div>
<div class="form-group">
<label class="control-label col-xs-8 col-sm-4 col-md-5" for="pw">Password:</label>
<div class="col-xs-10 col-sm-8 col-md-4">
<input type="password" class="form-control" id="pw" name="pw" placeholder="Password">
</div>
</div>
<br>
<button type="submit" class="btn btn-default"id="entra">Entra</button>
</form>


This is my Servlet:



    package Controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Logger;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class LoginServlet
*/
@WebServlet("/IROPLAS/Controller/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* Default constructor.
*/
public LoginServlet() {
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().append("Served at: ").append(request.getContextPath());
response.setContentType("text/html");

RequestDispatcher requestDispatcher;
String m=request.getParameter("mail");
String p=request.getParameter("pw");

if(Model.BUtente.validate(m, p)){
Model.BUtente u=Model.BUtente.getUtente(m, p);
request.setAttribute("utente", u);
requestDispatcher=request.getRequestDispatcher("/Success.html");
requestDispatcher.forward(request, response);
} //pagina profilo utente
else{
PrintWriter pw=response.getWriter();
response.sendRedirect(request.getContextPath()+"/Failure.html");
pw.close();
}//errore


}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}


Model.BUtente.validate(mail,pw) returns true if the user (with e-mail=mail and password=pw) is a record of my DB, else returns false, I've tested it and works fine.



These are my Success.html



    <!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Success
</body>
</html>


and my Failure.html



<!DOCTYPE html>

<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Fail
</body>
</html>









share|improve this question





























    0














    I have a problem with a school project, it's a little web dinamic project.
    In the Login page, if I submit parameters of a user that exist in my DB, all goes well and I have my "success.html" page, but if I submit parameters of a user that is not in my DB I have a 404 page, while I'm expecting my "failure.html".
    Could u please help me to find the error?



    I'm using:




    • Eclipse Java Neon

    • Tomcat 9.0.12


    This is my login form:



    <form id="login" class="form-horizontal" action="/IROPLAS/Controller/LoginServlet" method="GET">
    <div class="form-group">
    <label class="control-label col-xs-8 col-sm-4 col-md-5" for="mail">E-mail:</label>
    <div class="col-xs-10 col-sm-8 col-md-4">
    <input type="text" class="form-control" id="mail" name="mail" placeholder="E-mail">
    </div>
    </div>
    <div class="form-group">
    <label class="control-label col-xs-8 col-sm-4 col-md-5" for="pw">Password:</label>
    <div class="col-xs-10 col-sm-8 col-md-4">
    <input type="password" class="form-control" id="pw" name="pw" placeholder="Password">
    </div>
    </div>
    <br>
    <button type="submit" class="btn btn-default"id="entra">Entra</button>
    </form>


    This is my Servlet:



        package Controller;

    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.logging.Logger;

    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    /**
    * Servlet implementation class LoginServlet
    */
    @WebServlet("/IROPLAS/Controller/LoginServlet")
    public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
    * Default constructor.
    */
    public LoginServlet() {
    }

    /**
    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.getWriter().append("Served at: ").append(request.getContextPath());
    response.setContentType("text/html");

    RequestDispatcher requestDispatcher;
    String m=request.getParameter("mail");
    String p=request.getParameter("pw");

    if(Model.BUtente.validate(m, p)){
    Model.BUtente u=Model.BUtente.getUtente(m, p);
    request.setAttribute("utente", u);
    requestDispatcher=request.getRequestDispatcher("/Success.html");
    requestDispatcher.forward(request, response);
    } //pagina profilo utente
    else{
    PrintWriter pw=response.getWriter();
    response.sendRedirect(request.getContextPath()+"/Failure.html");
    pw.close();
    }//errore


    }

    /**
    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doGet(request, response);
    }
    }


    Model.BUtente.validate(mail,pw) returns true if the user (with e-mail=mail and password=pw) is a record of my DB, else returns false, I've tested it and works fine.



    These are my Success.html



        <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    Success
    </body>
    </html>


    and my Failure.html



    <!DOCTYPE html>

    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    Fail
    </body>
    </html>









    share|improve this question



























      0












      0








      0







      I have a problem with a school project, it's a little web dinamic project.
      In the Login page, if I submit parameters of a user that exist in my DB, all goes well and I have my "success.html" page, but if I submit parameters of a user that is not in my DB I have a 404 page, while I'm expecting my "failure.html".
      Could u please help me to find the error?



      I'm using:




      • Eclipse Java Neon

      • Tomcat 9.0.12


      This is my login form:



      <form id="login" class="form-horizontal" action="/IROPLAS/Controller/LoginServlet" method="GET">
      <div class="form-group">
      <label class="control-label col-xs-8 col-sm-4 col-md-5" for="mail">E-mail:</label>
      <div class="col-xs-10 col-sm-8 col-md-4">
      <input type="text" class="form-control" id="mail" name="mail" placeholder="E-mail">
      </div>
      </div>
      <div class="form-group">
      <label class="control-label col-xs-8 col-sm-4 col-md-5" for="pw">Password:</label>
      <div class="col-xs-10 col-sm-8 col-md-4">
      <input type="password" class="form-control" id="pw" name="pw" placeholder="Password">
      </div>
      </div>
      <br>
      <button type="submit" class="btn btn-default"id="entra">Entra</button>
      </form>


      This is my Servlet:



          package Controller;

      import java.io.IOException;
      import java.io.PrintWriter;
      import java.util.logging.Logger;

      import javax.servlet.RequestDispatcher;
      import javax.servlet.ServletException;
      import javax.servlet.annotation.WebServlet;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      /**
      * Servlet implementation class LoginServlet
      */
      @WebServlet("/IROPLAS/Controller/LoginServlet")
      public class LoginServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;

      /**
      * Default constructor.
      */
      public LoginServlet() {
      }

      /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      response.getWriter().append("Served at: ").append(request.getContextPath());
      response.setContentType("text/html");

      RequestDispatcher requestDispatcher;
      String m=request.getParameter("mail");
      String p=request.getParameter("pw");

      if(Model.BUtente.validate(m, p)){
      Model.BUtente u=Model.BUtente.getUtente(m, p);
      request.setAttribute("utente", u);
      requestDispatcher=request.getRequestDispatcher("/Success.html");
      requestDispatcher.forward(request, response);
      } //pagina profilo utente
      else{
      PrintWriter pw=response.getWriter();
      response.sendRedirect(request.getContextPath()+"/Failure.html");
      pw.close();
      }//errore


      }

      /**
      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      doGet(request, response);
      }
      }


      Model.BUtente.validate(mail,pw) returns true if the user (with e-mail=mail and password=pw) is a record of my DB, else returns false, I've tested it and works fine.



      These are my Success.html



          <!DOCTYPE html>
      <html>
      <head>
      <meta charset="ISO-8859-1">
      <title>Insert title here</title>
      </head>
      <body>
      Success
      </body>
      </html>


      and my Failure.html



      <!DOCTYPE html>

      <html>
      <head>
      <meta charset="ISO-8859-1">
      <title>Insert title here</title>
      </head>
      <body>
      Fail
      </body>
      </html>









      share|improve this question















      I have a problem with a school project, it's a little web dinamic project.
      In the Login page, if I submit parameters of a user that exist in my DB, all goes well and I have my "success.html" page, but if I submit parameters of a user that is not in my DB I have a 404 page, while I'm expecting my "failure.html".
      Could u please help me to find the error?



      I'm using:




      • Eclipse Java Neon

      • Tomcat 9.0.12


      This is my login form:



      <form id="login" class="form-horizontal" action="/IROPLAS/Controller/LoginServlet" method="GET">
      <div class="form-group">
      <label class="control-label col-xs-8 col-sm-4 col-md-5" for="mail">E-mail:</label>
      <div class="col-xs-10 col-sm-8 col-md-4">
      <input type="text" class="form-control" id="mail" name="mail" placeholder="E-mail">
      </div>
      </div>
      <div class="form-group">
      <label class="control-label col-xs-8 col-sm-4 col-md-5" for="pw">Password:</label>
      <div class="col-xs-10 col-sm-8 col-md-4">
      <input type="password" class="form-control" id="pw" name="pw" placeholder="Password">
      </div>
      </div>
      <br>
      <button type="submit" class="btn btn-default"id="entra">Entra</button>
      </form>


      This is my Servlet:



          package Controller;

      import java.io.IOException;
      import java.io.PrintWriter;
      import java.util.logging.Logger;

      import javax.servlet.RequestDispatcher;
      import javax.servlet.ServletException;
      import javax.servlet.annotation.WebServlet;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      /**
      * Servlet implementation class LoginServlet
      */
      @WebServlet("/IROPLAS/Controller/LoginServlet")
      public class LoginServlet extends HttpServlet {
      private static final long serialVersionUID = 1L;

      /**
      * Default constructor.
      */
      public LoginServlet() {
      }

      /**
      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      response.getWriter().append("Served at: ").append(request.getContextPath());
      response.setContentType("text/html");

      RequestDispatcher requestDispatcher;
      String m=request.getParameter("mail");
      String p=request.getParameter("pw");

      if(Model.BUtente.validate(m, p)){
      Model.BUtente u=Model.BUtente.getUtente(m, p);
      request.setAttribute("utente", u);
      requestDispatcher=request.getRequestDispatcher("/Success.html");
      requestDispatcher.forward(request, response);
      } //pagina profilo utente
      else{
      PrintWriter pw=response.getWriter();
      response.sendRedirect(request.getContextPath()+"/Failure.html");
      pw.close();
      }//errore


      }

      /**
      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
      */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      // TODO Auto-generated method stub
      doGet(request, response);
      }
      }


      Model.BUtente.validate(mail,pw) returns true if the user (with e-mail=mail and password=pw) is a record of my DB, else returns false, I've tested it and works fine.



      These are my Success.html



          <!DOCTYPE html>
      <html>
      <head>
      <meta charset="ISO-8859-1">
      <title>Insert title here</title>
      </head>
      <body>
      Success
      </body>
      </html>


      and my Failure.html



      <!DOCTYPE html>

      <html>
      <head>
      <meta charset="ISO-8859-1">
      <title>Insert title here</title>
      </head>
      <body>
      Fail
      </body>
      </html>






      html servlets http-status-code-404 url-redirection httpresponse






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 11:55

























      asked Nov 21 '18 at 11:50









      Chiara Bufalino

      63




      63
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I did it!
          If u have the same problem I'm posting here my solution:



          My login form:



          <form id="login" class="form-horizontal" action="LoginServlet" method="GET">
          <div class="form-group">
          <label class="control-label col-xs-8 col-sm-4 col-md-5" for="mail">E-mail:</label>
          <div class="col-xs-10 col-sm-8 col-md-4">
          <input type="text" class="form-control" id="mail" name="mail" placeholder="E-mail">
          </div>
          </div>
          <div class="form-group">
          <label class="control-label col-xs-8 col-sm-4 col-md-5" for="pw">Password:</label>
          <div class="col-xs-10 col-sm-8 col-md-4">
          <input type="password" class="form-control" id="pw" name="pw" placeholder="Password">
          </div>
          </div>
          <br>
          <button type="submit" class="btn btn-default"id="entra">Entra</button>
          </form>


          My Servlet:



          package Controller;

          import java.io.IOException;
          import java.io.PrintWriter;
          import java.util.logging.Logger;

          import javax.servlet.RequestDispatcher;
          import javax.servlet.ServletException;
          import javax.servlet.annotation.WebServlet;
          import javax.servlet.http.HttpServlet;
          import javax.servlet.http.HttpServletRequest;
          import javax.servlet.http.HttpServletResponse;

          /**
          * Servlet implementation class LoginServlet
          */
          //@WebServlet("/IROPLAS/Controller/LoginServlet")
          @WebServlet("/LoginServlet")
          public class LoginServlet extends HttpServlet {
          private static final long serialVersionUID = 1L;

          /**
          * Default constructor.
          */
          public LoginServlet() {
          }

          /**
          * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
          */
          protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          response.getWriter().append("Served at: ").append(request.getContextPath());
          response.setContentType("text/html");

          RequestDispatcher requestDispatcher;
          String m=request.getParameter("mail");
          String p=request.getParameter("pw");

          if(Model.BUtente.validate(m, p)){
          Model.BUtente u=Model.BUtente.getUtente(m, p);
          request.setAttribute("utente", u);
          requestDispatcher=request.getRequestDispatcher("/Success.html");
          requestDispatcher.forward(request, response);
          } //pagina profilo utente
          else{ //404 not found
          PrintWriter pw=response.getWriter();
          response.sendRedirect("Failure.html");
          pw.close();
          }//errore


          }

          /**
          * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
          */
          protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
          doGet(request, response);
          }

          }





          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',
            autoActivateHeartbeat: false,
            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%2f53411430%2f404-error-while-redirecting-to-html-from-a-servlet%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I did it!
            If u have the same problem I'm posting here my solution:



            My login form:



            <form id="login" class="form-horizontal" action="LoginServlet" method="GET">
            <div class="form-group">
            <label class="control-label col-xs-8 col-sm-4 col-md-5" for="mail">E-mail:</label>
            <div class="col-xs-10 col-sm-8 col-md-4">
            <input type="text" class="form-control" id="mail" name="mail" placeholder="E-mail">
            </div>
            </div>
            <div class="form-group">
            <label class="control-label col-xs-8 col-sm-4 col-md-5" for="pw">Password:</label>
            <div class="col-xs-10 col-sm-8 col-md-4">
            <input type="password" class="form-control" id="pw" name="pw" placeholder="Password">
            </div>
            </div>
            <br>
            <button type="submit" class="btn btn-default"id="entra">Entra</button>
            </form>


            My Servlet:



            package Controller;

            import java.io.IOException;
            import java.io.PrintWriter;
            import java.util.logging.Logger;

            import javax.servlet.RequestDispatcher;
            import javax.servlet.ServletException;
            import javax.servlet.annotation.WebServlet;
            import javax.servlet.http.HttpServlet;
            import javax.servlet.http.HttpServletRequest;
            import javax.servlet.http.HttpServletResponse;

            /**
            * Servlet implementation class LoginServlet
            */
            //@WebServlet("/IROPLAS/Controller/LoginServlet")
            @WebServlet("/LoginServlet")
            public class LoginServlet extends HttpServlet {
            private static final long serialVersionUID = 1L;

            /**
            * Default constructor.
            */
            public LoginServlet() {
            }

            /**
            * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
            */
            protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.getWriter().append("Served at: ").append(request.getContextPath());
            response.setContentType("text/html");

            RequestDispatcher requestDispatcher;
            String m=request.getParameter("mail");
            String p=request.getParameter("pw");

            if(Model.BUtente.validate(m, p)){
            Model.BUtente u=Model.BUtente.getUtente(m, p);
            request.setAttribute("utente", u);
            requestDispatcher=request.getRequestDispatcher("/Success.html");
            requestDispatcher.forward(request, response);
            } //pagina profilo utente
            else{ //404 not found
            PrintWriter pw=response.getWriter();
            response.sendRedirect("Failure.html");
            pw.close();
            }//errore


            }

            /**
            * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
            */
            protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request, response);
            }

            }





            share|improve this answer


























              0














              I did it!
              If u have the same problem I'm posting here my solution:



              My login form:



              <form id="login" class="form-horizontal" action="LoginServlet" method="GET">
              <div class="form-group">
              <label class="control-label col-xs-8 col-sm-4 col-md-5" for="mail">E-mail:</label>
              <div class="col-xs-10 col-sm-8 col-md-4">
              <input type="text" class="form-control" id="mail" name="mail" placeholder="E-mail">
              </div>
              </div>
              <div class="form-group">
              <label class="control-label col-xs-8 col-sm-4 col-md-5" for="pw">Password:</label>
              <div class="col-xs-10 col-sm-8 col-md-4">
              <input type="password" class="form-control" id="pw" name="pw" placeholder="Password">
              </div>
              </div>
              <br>
              <button type="submit" class="btn btn-default"id="entra">Entra</button>
              </form>


              My Servlet:



              package Controller;

              import java.io.IOException;
              import java.io.PrintWriter;
              import java.util.logging.Logger;

              import javax.servlet.RequestDispatcher;
              import javax.servlet.ServletException;
              import javax.servlet.annotation.WebServlet;
              import javax.servlet.http.HttpServlet;
              import javax.servlet.http.HttpServletRequest;
              import javax.servlet.http.HttpServletResponse;

              /**
              * Servlet implementation class LoginServlet
              */
              //@WebServlet("/IROPLAS/Controller/LoginServlet")
              @WebServlet("/LoginServlet")
              public class LoginServlet extends HttpServlet {
              private static final long serialVersionUID = 1L;

              /**
              * Default constructor.
              */
              public LoginServlet() {
              }

              /**
              * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
              */
              protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              response.getWriter().append("Served at: ").append(request.getContextPath());
              response.setContentType("text/html");

              RequestDispatcher requestDispatcher;
              String m=request.getParameter("mail");
              String p=request.getParameter("pw");

              if(Model.BUtente.validate(m, p)){
              Model.BUtente u=Model.BUtente.getUtente(m, p);
              request.setAttribute("utente", u);
              requestDispatcher=request.getRequestDispatcher("/Success.html");
              requestDispatcher.forward(request, response);
              } //pagina profilo utente
              else{ //404 not found
              PrintWriter pw=response.getWriter();
              response.sendRedirect("Failure.html");
              pw.close();
              }//errore


              }

              /**
              * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
              */
              protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              // TODO Auto-generated method stub
              doGet(request, response);
              }

              }





              share|improve this answer
























                0












                0








                0






                I did it!
                If u have the same problem I'm posting here my solution:



                My login form:



                <form id="login" class="form-horizontal" action="LoginServlet" method="GET">
                <div class="form-group">
                <label class="control-label col-xs-8 col-sm-4 col-md-5" for="mail">E-mail:</label>
                <div class="col-xs-10 col-sm-8 col-md-4">
                <input type="text" class="form-control" id="mail" name="mail" placeholder="E-mail">
                </div>
                </div>
                <div class="form-group">
                <label class="control-label col-xs-8 col-sm-4 col-md-5" for="pw">Password:</label>
                <div class="col-xs-10 col-sm-8 col-md-4">
                <input type="password" class="form-control" id="pw" name="pw" placeholder="Password">
                </div>
                </div>
                <br>
                <button type="submit" class="btn btn-default"id="entra">Entra</button>
                </form>


                My Servlet:



                package Controller;

                import java.io.IOException;
                import java.io.PrintWriter;
                import java.util.logging.Logger;

                import javax.servlet.RequestDispatcher;
                import javax.servlet.ServletException;
                import javax.servlet.annotation.WebServlet;
                import javax.servlet.http.HttpServlet;
                import javax.servlet.http.HttpServletRequest;
                import javax.servlet.http.HttpServletResponse;

                /**
                * Servlet implementation class LoginServlet
                */
                //@WebServlet("/IROPLAS/Controller/LoginServlet")
                @WebServlet("/LoginServlet")
                public class LoginServlet extends HttpServlet {
                private static final long serialVersionUID = 1L;

                /**
                * Default constructor.
                */
                public LoginServlet() {
                }

                /**
                * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
                */
                protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                response.getWriter().append("Served at: ").append(request.getContextPath());
                response.setContentType("text/html");

                RequestDispatcher requestDispatcher;
                String m=request.getParameter("mail");
                String p=request.getParameter("pw");

                if(Model.BUtente.validate(m, p)){
                Model.BUtente u=Model.BUtente.getUtente(m, p);
                request.setAttribute("utente", u);
                requestDispatcher=request.getRequestDispatcher("/Success.html");
                requestDispatcher.forward(request, response);
                } //pagina profilo utente
                else{ //404 not found
                PrintWriter pw=response.getWriter();
                response.sendRedirect("Failure.html");
                pw.close();
                }//errore


                }

                /**
                * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
                */
                protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
                doGet(request, response);
                }

                }





                share|improve this answer












                I did it!
                If u have the same problem I'm posting here my solution:



                My login form:



                <form id="login" class="form-horizontal" action="LoginServlet" method="GET">
                <div class="form-group">
                <label class="control-label col-xs-8 col-sm-4 col-md-5" for="mail">E-mail:</label>
                <div class="col-xs-10 col-sm-8 col-md-4">
                <input type="text" class="form-control" id="mail" name="mail" placeholder="E-mail">
                </div>
                </div>
                <div class="form-group">
                <label class="control-label col-xs-8 col-sm-4 col-md-5" for="pw">Password:</label>
                <div class="col-xs-10 col-sm-8 col-md-4">
                <input type="password" class="form-control" id="pw" name="pw" placeholder="Password">
                </div>
                </div>
                <br>
                <button type="submit" class="btn btn-default"id="entra">Entra</button>
                </form>


                My Servlet:



                package Controller;

                import java.io.IOException;
                import java.io.PrintWriter;
                import java.util.logging.Logger;

                import javax.servlet.RequestDispatcher;
                import javax.servlet.ServletException;
                import javax.servlet.annotation.WebServlet;
                import javax.servlet.http.HttpServlet;
                import javax.servlet.http.HttpServletRequest;
                import javax.servlet.http.HttpServletResponse;

                /**
                * Servlet implementation class LoginServlet
                */
                //@WebServlet("/IROPLAS/Controller/LoginServlet")
                @WebServlet("/LoginServlet")
                public class LoginServlet extends HttpServlet {
                private static final long serialVersionUID = 1L;

                /**
                * Default constructor.
                */
                public LoginServlet() {
                }

                /**
                * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
                */
                protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                response.getWriter().append("Served at: ").append(request.getContextPath());
                response.setContentType("text/html");

                RequestDispatcher requestDispatcher;
                String m=request.getParameter("mail");
                String p=request.getParameter("pw");

                if(Model.BUtente.validate(m, p)){
                Model.BUtente u=Model.BUtente.getUtente(m, p);
                request.setAttribute("utente", u);
                requestDispatcher=request.getRequestDispatcher("/Success.html");
                requestDispatcher.forward(request, response);
                } //pagina profilo utente
                else{ //404 not found
                PrintWriter pw=response.getWriter();
                response.sendRedirect("Failure.html");
                pw.close();
                }//errore


                }

                /**
                * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
                */
                protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                // TODO Auto-generated method stub
                doGet(request, response);
                }

                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 13:05









                Chiara Bufalino

                63




                63






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53411430%2f404-error-while-redirecting-to-html-from-a-servlet%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    TypeError: fit_transform() missing 1 required positional argument: 'X'