Архитектура MVC NullPointerException при просмотре - PullRequest
0 голосов
/ 04 июня 2018

Доброе утро,

Итак, я нашел причину проблемы, причиной стал мой файл persistence.xml, но теперь у меня есть другая проблема,

Когда мой клиент постояннои я хочу просмотреть своих клиентов, следующее исключение выдается NullPointerException, следующее - трассировка стека

2018-06-04 10:03:32,728 ERROR [stderr] (default task-1) java.lang.NullPointerException
2018-06-04 10:03:32,728 ERROR [stderr] (default task-1) at psybergate.grad2018.javafnds.developer.presentation.CustomerController.showAllCustomers(Unknown Source)
2018-06-04 10:03:32,729 ERROR [stderr] (default task-1) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-06-04 10:03:32,733 ERROR [stderr] (default task-1) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2018-06-04 10:03:32,733 ERROR [stderr] (default task-1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-06-04 10:03:32,734 ERROR [stderr] (default task-1) at java.lang.reflect.Method.invoke(Method.java:497)
2018-06-04 10:03:32,734 ERROR [stderr] (default task-1) at psybergate.grad2018.javafnds.framework.DispatchServlet.doGet(Unknown Source)
2018-06-04 10:03:32,735 ERROR [stderr] (default task-1) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
2018-06-04 10:03:32,736 ERROR [stderr] (default task-1) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
2018-06-04 10:03:32,736 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
2018-06-04 10:03:32,741 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
2018-06-04 10:03:32,745 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:67)
2018-06-04 10:03:32,745 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
2018-06-04 10:03:32,745 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
2018-06-04 10:03:32,746 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,746 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
2018-06-04 10:03:32,747 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
2018-06-04 10:03:32,747 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,747 ERROR [stderr] (default task-1) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
2018-06-04 10:03:32,748 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
2018-06-04 10:03:32,748 ERROR [stderr] (default task-1) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
2018-06-04 10:03:32,749 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
2018-06-04 10:03:32,749 ERROR [stderr] (default task-1) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
2018-06-04 10:03:32,750 ERROR [stderr] (default task-1) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
2018-06-04 10:03:32,756 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,756 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
2018-06-04 10:03:32,757 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,758 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
2018-06-04 10:03:32,758 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,759 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
2018-06-04 10:03:32,759 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
2018-06-04 10:03:32,760 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
2018-06-04 10:03:32,760 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
2018-06-04 10:03:32,761 ERROR [stderr] (default task-1) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
2018-06-04 10:03:32,766 ERROR [stderr] (default task-1) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
2018-06-04 10:03:32,766 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
2018-06-04 10:03:32,767 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction$$Lambda$848/1377163296.call(Unknown Source)
2018-06-04 10:03:32,767 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,768 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
2018-06-04 10:03:32,768 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,769 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
018-06-04 10:03:32,769 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,770 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
2018-06-04 10:03:32,771 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,775 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
2018-06-04 10:03:32,778 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,778 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
2018-06-04 10:03:32,779 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
2018-06-04 10:03:32,779 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
2018-06-04 10:03:32,780 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
2018-06-04 10:03:32,781 ERROR [stderr] (default task-1) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)
2018-06-04 10:03:32,781 ERROR [stderr] (default task-1) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
2018-06-04 10:03:32,782 ERROR [stderr] (default task-1) at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
2018-06-04 10:03:32,782 ERROR [stderr] (default task-1) at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
2018-06-04 10:03:32,783 ERROR [stderr] (default task-1) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
2018-06-04 10:03:32,783 ERROR [stderr] (default task-1) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1378)
2018-06-04 10:03:32,784 ERROR [stderr] (default task-1) at java.lang.Thread.run(Thread.java:745)
2018-06-04 10:03:32,792 ERROR [stderr] (default task-1) java.lang.NullPointerException
2018-06-04 10:03:32,792 ERROR [stderr] (default task-1) at psybergate.grad2018.javafnds.developer.presentation.CustomerController.showAllCustomers(Unknown Source)
2018-06-04 10:03:32,793 ERROR [stderr] (default task-1) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-06-04 10:03:32,793 ERROR [stderr] (default task-1) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2018-06-04 10:03:32,794 ERROR [stderr] (default task-1) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-06-04 10:03:32,796 ERROR [stderr] (default task-1) at java.lang.reflect.Method.invoke(Method.java:497)

2018-06-04 10:03:32,796 ERROR [stderr] (default task-1) at psybergate.grad2018.javafnds.framework.DispatchServlet.doGet(Unknown Source)
2018-06-04 10:03:32,800 ERROR [stderr] (default task-1) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
2018-06-04 10:03:32,800 ERROR [stderr] (default task-1) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
2018-06-04 10:03:32,801 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74)
2018-06-04 10:03:32,801 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
2018-06-04 10:03:32,802 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletChain$1.handleRequest(ServletChain.java:67)
2018-06-04 10:03:32,802 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
2018-06-04 10:03:32,803 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
2018-06-04 10:03:32,803 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,804 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
2018-06-04 10:03:32,804 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
2018-06-04 10:03:32,807 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,812 ERROR [stderr] (default task-1) at io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
2018-06-04 10:03:32,812 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
2018-06-04 10:03:32,813 ERROR [stderr] (default task-1) at io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
2018-06-04 10:03:32,813 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
2018-06-04 10:03:32,814 ERROR [stderr] (default task-1) at io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
2018-06-04 10:03:32,814 ERROR [stderr] (default task-1) at io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
2018-06-04 10:03:32,815 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,816 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
2018-06-04 10:03:32,816 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,818 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.GlobalRequestControllerHandler.handleRequest(GlobalRequestControllerHandler.java:68)
2018-06-04 10:03:32,823 ERROR [stderr] (default task-1) at io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
2018-06-04 10:03:32,824 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
2018-06-04 10:03:32,825 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
2018-06-04 10:03:32,825 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
2018-06-04 10:03:32,825 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
2018-06-04 10:03:32,826 ERROR [stderr] (default task-1) at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
2018-06-04 10:03:32,826 ERROR [stderr] (default task-1) at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
2018-06-04 10:03:32,827 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)
2018-06-04 10:03:32,827 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction$$Lambda$848/1377163296.call(Unknown Source)
2018-06-04 10:03:32,828 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,829 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
2018-06-04 10:03:32,829 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,830 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
2018-06-04 10:03:32,830 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,834 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
2018-06-04 10:03:32,835 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,836 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
2018-06-04 10:03:32,837 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1526)
2018-06-04 10:03:32,838 ERROR [stderr] (default task-1) at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction$$Lambda$849/1714042072.call(Unknown Source)
2018-06-04 10:03:32,839 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
2018-06-04 10:03:32,840 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
2018-06-04 10:03:32,840 ERROR [stderr] (default task-1) at io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
2018-06-04 10:03:32,841 ERROR [stderr] (default task-1) at io.undertow.server.Connectors.executeRootHandler(Connectors.java:360)
2018-06-04 10:03:32,841 ERROR [stderr] (default task-1) at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
2018-06-04 10:03:32,842 ERROR [stderr] (default task-1) at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
2018-06-04 10:03:32,842 ERROR [stderr] (default task-1) at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
2018-06-04 10:03:32,843 ERROR [stderr] (default task-1) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
2018-06-04 10:03:32,847 ERROR [stderr] (default task-1) at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run EnhancedQueueExecutor.java:1378)
2018-06-04 10:03:32,848 ERROR [stderr] (default task-1) at java.lang.Thread.run(Thread.java:745)

Я не могу просматривать клиентов, вот мой код jsp

<%@ page import="java.io.*, java.util.*"%>
  <!DOCTYPE html>
  <html>

  <head>
    <title>Customer Added</title>
    <style type="text/css">
      .defaultheader {
        overflow: hidden;
        position: fixed;
        background-color: #f1f1f1;
        padding: 20px 10px;
        top: 0px;
        left: 0px;
        width: 100%;
        background-color: #ddd;
        color: white;
        text-align: center;
      }
      
      .container {
        padding: 40px;
        text-align: center;
      }
      
      hr {
        border: 1px solid #f1f1f1;
        margin-bottom: 25px;
      }
      /* Set a style for the submit/register button */
      
      .registerbtn {
        background-color: #4CAF50;
        color: white;
        padding: 16px 20px;
        margin: 8px 0;
        border: none;
        cursor: pointer;
        width: 100%;
        opacity: 0.9;
        text-decoration: none;
      }
      
      .registerbtn:hover {
        opacity: 1;
      }
      /* Add a blue text color to links */
      
      a {
        color: dodgerblue;
      }
      
      .footer {
        position: fixed;
        left: 0;
        bottom: 0;
        width: 100%;
        padding-top: 20px;
        background-color: #ddd;
        color: black;
        text-align: center;
      }
    </style>
  </head>

  <body>
    <div class="defaultheader">
      <div class="header-right"></div>
    </div>
    <div class="container">
      <h1>Customer Added Successfully</h1>
      <hr>
      <h1><a class="registerbtn" href="viewcustomers">View All Customers</a></h1>
    </div>
    <div class="footer"></div>
  </body>

  </html>

мой CustomerController

package psybergate.grad2018.javafnds.developer.presentation;

import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.util.List;

import javax.naming.InitialContext;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import psybergate.grad2018.javafnds.developer.service.CustomerServiceSessionBean;
import psybergate.grad2018.javafnds.domain.Customer;
import psybergate.grad2018.javafnds.framework.Controller;

/**
 * @since 31 May 2018
 * @author christiaan.dotze
 */
public class CustomerController implements Controller {

    private Logger logger = LogManager.getLogger(CustomerController.class);

    private CustomerServiceSessionBean customerBean;

    public void displayForm(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        try {
            logger.info("attempting to load jsp");
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("/WEB-INF/views/addCustomerForm.jsp");
            requestDispatcher.forward(req, resp);
            logger.info("jsp loaded");
        }
        catch (Exception e) {
            logger.info("Error 404 - page not found:" + e);
            throw new RuntimeException(e);
        }
    }

    public void registerCustomer(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        try {
            Long customerNumber = Long.parseLong(req.getParameter("customernumber"));
            String firstName = req.getParameter("firstname");
            String lastName = req.getParameter("lastname");
            String[] dateString = (req.getParameter("dateOfBirth")).split("-");
            int year = Integer.parseInt(dateString[0]);
            int month = Integer.parseInt(dateString[1]);
            int day = Integer.parseInt(dateString[2]);
            LocalDate dateOfBirth = LocalDate.of(year, month, day);
            customerBean = (CustomerServiceSessionBean) new InitialContext()
                    .lookup("java:app/hw7b/CustomerServiceSessionBean");
            Customer customer = new Customer(customerNumber, firstName, lastName, dateOfBirth);
            logger.info("Customer created");
            customerBean.registerCustomer(customer);
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("/WEB-INF/views/customerAdded.jsp");
            requestDispatcher.forward(req, resp);
        }
        catch (Exception e) {
            PrintWriter out = resp.getWriter();
            out.println("Customer not added: " + e);
            e.printStackTrace();
            logger.info("Customer not added: " + e);
            throw new RuntimeException("ERROR:", e);// exception is thrown here
        }
    }

    public void showAllCustomers(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        try {
            List<Customer> customers = customerBean.listAllCustomers();
            logger.info("list of customers");
            req.setAttribute("customers", customers);
            RequestDispatcher requestDispatcher = req.getRequestDispatcher("/WEB-INF/views/displayCustomers.jsp");
            requestDispatcher.forward(req, resp);
            logger.info("forwarded to jsp");
        }
        catch (Exception e) {
            e.printStackTrace();
            PrintWriter out = resp.getWriter();
            e.printStackTrace();
            out.println("no customers: " + e);
            throw new IOException();//NullPointerException thrown
        }

    }
}

и наконец, мои свойства

/registercustomer:psybergate.grad2018.javafnds.developer.presentation.CustomerController/registerCustomer /registercustomerform:psybergate.grad2018.javafnds.developer.presentation.CustomerController/displayForm /viewcustomers:psybergate.grad2018.javafnds.developer.presentation.CustomerController/showAllCustomers

1 Ответ

0 голосов
/ 04 июня 2018

Я обнаружил проблему, я все еще новичок в этом и не делал поиск при попытке просмотреть моих клиентов

...