Hello guys! I am using netbeans8.1 and apache Tomcat8.0.27.0

I am making a simple web application for practice. I have made two html pages "index.html" and "welcome.html".

On page index.html I am taking two parameters from user 'name' and 'sirName'. If user enters Saboor and Siddique in 'name' and 'sirName' respectively then my servlet redirects reponse to the page"welcom.html" which shows a welcome message to user, else my servlets redirects to user to an error page and prints an error message which I have hardcoded in my servlet.
But when I run my project, "index.html" appears and when I enter above two names in textboxes and hit submit button one of two situations occur, either there displays error 404:Indicates that the requested resource is not available, or error http 500 occurs showing : The server encountered an internal error that prevented it from fulfilling this request.

I am pasting code for my four files(servlet file, web.xml, index.html, welcome.html) below .Please guide me that what problem is occuring.

Code of Servlet:

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class myservlet4 extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");

String fName = request.getParameter("firstName");
 String sName = request.getParameter("sirName");

if(fName.equals("Saboor")&& sName.equals("Siddique"))
 {


    response.sendRedirect("welcome.html");
  }
  else

  {
     response.sendError(HttpServletResponse.SC_PROXY_AUTHENTICATION_REQUIRED, "Send Error Demo");

 }// end else

    }



protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }


 protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }


}

Code of index.html:

<html> <head> <title>MyLoginPage</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body bgcolor = "skyblue"> <br></br> <br></br> <form method="Post"  action = "http://localhost:8084/Redirectionex/myservlet4" name = "loginform"> <table> <tr> <td> Enter Name:</td> <td> <input type = "text" name = "firstName" ></td> </tr> <tr> <td>Enter surName:</td> <td><input type = "text" name = "surName" ></td> </tr> <tr> <td colspan = "2" align = "right"> <input type = "submit" value = "Submit Form"> </td> </tr> </table> </form> </body> </html>

Code of Welcome.html:

<html> <head> <title>WelcomePage</title> </head> <body  bgcolor = "skyblue"> <h1>Welcome</h1> </body> </html>

Code of web.xml:

<?xml version="1.0" encoding="UTF-8"?> <web-app> <servlet> <servlet-name>myservlet4</servlet-name> <servlet-class>myservlet4</servlet-class> </servlet> <servlet-mapping> <servlet-name>myservlet4</servlet-name> <url-pattern>/myservlet4</url-pattern> </servlet-mapping> <session-config> <session-timeout>
            30
        </session-timeout> </session-config> </web-app> 
This article has been dead for over six months. Start a new discussion instead.