0

It is a login form using an excel file as database. A jsp page with form and a servlet page is created. When servlet annotation is given in the servlet page, the server is not getting started.

I am using Eclipse photon and tomcat 9.xxx server. Also added apache poi jar files in the library. If we comment @WebServlet("xxxx") the server gets started. There is no web.xml file is created.

@WebServlet("/validateLogin")
public class validateLogin extends HttpServlet {
    private static final long serialVersionUID = 1L;

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

    try {
        doGet(request, response);

        response.setContentType("text/html");
        PrintWriter write=response.getWriter();
        String username = request.getParameter("Username");
        String password = request.getParameter("Password");

        FileInputStream file = new FileInputStream(new File("userData.xlsx"));
        XSSFWorkbook workbook = new XSSFWorkbook(file);
        Sheet sheet = workbook.getSheetAt(0);
        Iterator<Row> rowIterator = sheet.iterator();

        while (rowIterator.hasNext()) {

            // Next row.
            Row row = rowIterator.next();

            // Get column records.
            Cell column1 = row.getCell(0);
            Cell column2 = row.getCell(1);

            // Read records.
            if (column1 != null && column2 != null) {

                String recordUsername = ""; 
                String recordPassword = "";

                if (column1.getCellType().toString().contains("STRING")) {
                    recordUsername = column1.getStringCellValue();
                } else if (column1.getCellType().toString().contains("NUMERIC")) {
                    recordUsername = Integer.toString((int)column1.getNumericCellValue());
                }

                if (column2.getCellType().toString().contains("STRING")) {
                    recordPassword = column2.getStringCellValue();
                } else if (column2.getCellType().toString().contains("NUMERIC")) {
                    recordPassword = Integer.toString((int)column2.getNumericCellValue());
                }


                if (username.equals(recordUsername) && password.equals(recordPassword)) {

                    RequestDispatcher rd=request.getRequestDispatcher("logged.jsp");
                    rd.forward(request, response); 
                } else {
                    write.print("Invalid");
                    RequestDispatcher rd=request.getRequestDispatcher("viewLogin.jsp");
                    rd.include(request, response); 

               }
            }  

            }

        file.close();
        workbook.close();    
        write.close();
           }
    catch(NullPointerException e) {
        System.out.println(e);  

    }
    catch(FileNotFoundException e) {
        System.out.println(e);
    }
    catch(IOException e) {
        System.out.println(e);
    }

When trying to start server it shows Server encountered with a problem and faild to start.

Vignesh
  • 17
  • 5

0 Answers0