0

I am running tomcat 7. i have build mysql db on my local computer when i try to run jsp file i get HTTP status 404 or HTTP status 500. i read all the q&a here, and did not find the answer. sorry for the mess, I am new at servlet....

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_3_0.xsd" version="3.0">
  <display-name>todolistservlet</display-name>
  <welcome-file-list>
    <welcome-file> ToDoListLogin.jsp</welcome-file>
    <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>
    <servlet-name>login</servlet-name>
    <servlet-class>Controller</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/ToDoListLogin.jsp</url-pattern>
  </servlet-mapping>
</web-app>

ToDoListLogin.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
<title>To Do List Login Page</title>

    <!-- Bootstrap core CSS -->
    <link href="../css/bootstrap.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="../css/custom.css" rel="stylesheet">
</head>
<body background="./ToDoListWebPic/icon1.png" style="background-size:62%;">

    <%
    String authentication = (String)request.getSession().getAttribute("authentication");


    %>
        <div class="sign-container">
            <div class="container">
                <%
                    if (authentication != null && authentication == "false")
                    {
                %>
                        <div class="alert alert-danger" style="margin-top:0;">
                            <strong>user id and/or Password Incorrect!</strong>
                        </div>
                <%

                    }
                %>
                  <form action="loginServlet" method="get" class="form-signin">
                  <h1 class="form-signin-heading text-primary">Wellcom to MyToDoList </h1>
                    <h2 class="form-signin-heading text-primary">Please sign in</h2>

                    <label for="inputUserId" class="sr-only">user Id</label>
                    <input type="text" id="inputuserId" name="userId" class="form-control"  />
                    </div>
                    <div>
                    <label for="inputPassword" class="sr-only">Password</label>
                    <input type="password" id="inputPassword" name="password" class="form-control"  />

                    <div>
                        <button class="btn btn-primary btn-lg"  type="submit" onsubmit="EncryptorPass.encryptPassword(password)" >Sign in</button>
                        </div>
                        <div>
                        <a href="signup"  class="btn btn-default btn-lg">Sign Up</a>
                    </div>
                  </form>

            </div> <!-- /container -->

         </div>
  </body>
</html>`

loginServlet.java

package Controller;

import java.io.IOException;
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;
import model.IToDoListDAO;
import model.ToDoListException;

/**
 * Servlet implementation class loginServlet
 */
@WebServlet("/loginServlet")
public class loginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private IToDoListDAO dao = IToDoListDAO.getInstance();
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String encryptedPass = null;

        request.getSession().getAttribute("currentList");
        (String)request.getSession().getAttribute("currentItem");

        EncryptorPass.encryptPassword(request.getParameter("password"));
            boolean isUserExists;
            int user = Integer.parseInt(userId);
            try {
                RequestDispatcher rd = null;
                isUserExists = dao.UserAuthentication( user, pwd);
                if (isUserExists)
                {
//  set authentication credentials into session

                        request.getSession().setAttribute("fullName", dao.getAllUsers());

                    request.getSession().setAttribute("userId", request.getParameter("userId"));
                    response.sendRedirect("home");
                }
                else
                {
                    request.getSession().setAttribute("authentication", "false");
                    response.sendRedirect("ToDoListLogin");
                    rd = request.getRequestDispatcher("/errorpage.jsp");
                }
                rd.forward(request, response);

            } catch (ToDoListException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
orly.sharon
  • 149
  • 1
  • 9

1 Answers1

0

put just

@WebServlet("/loginServlet")

and remove from web.xml file

<servlet>
    <servlet-name>login</servlet-name>
    <servlet-class>Controller</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>/ToDoListLogin.jsp</url-pattern>
  </servlet-mapping>
Taha
  • 1,072
  • 2
  • 16
  • 29
  • hi tank you for your quick reply, i treid it . now i get HTTP Status 500 - Error instantiating servlet class class name type Exception report message Error instantiating servlet class il.ac.hit.samples.sharon.orly.ToDoList.Controller description The server encountered an internal error that prevented it from fulfilling this request. exception javax.servlet.ServletException: Error instantiating servlet class class name – orly.sharon Jun 25 '16 at 18:44
  • hi, now i get HTTP Status 500 - Unable to compile class for JSP: type Exception report message Unable to compile class for JSP: description The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: [31] in the generated java file: – orly.sharon Jun 25 '16 at 19:19