title: The server encountered an internal error that prevented it from fulfilling this request - in servlet 3.0
body: <p>I want to run easy registration <code>jsp</code> page with <code>servlet</code>. And it throw this error message:</p>
  
  <pre><code>description The server encountered an internal error that prevented it from fulfilling this request.
  
  java.lang.NullPointerException
      com.java.task11.utils.ValidationUtils.isEmailValid(ValidationUtils.java:22)
      com.java.task11.webapp.RegistrationServlet.validateInputs(RegistrationServlet.java:95)
      com.java.task11.webapp.RegistrationServlet.processRegistration(RegistrationServlet.java:66)
      com.java.task11.webapp.RegistrationServlet.doPost(RegistrationServlet.java:39)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  </code></pre>
  
  <p>Here is my <code>registration.jsp</code>:</p>
  
  <pre><code>&lt;%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %&gt;
  
  &lt;c:set var="language"
         value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}"
         scope="session"/&gt;
  &lt;fmt:setLocale value="${language}"/&gt;
  &lt;fmt:setBundle basename="com.java.task11.i18n.text"/&gt;
  
  &lt;html lang="${language}"&gt;
  &lt;head&gt;
      &lt;title&gt;Registration&lt;/title&gt;
      &lt;jsp:include page="parts/header.jsp"/&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;div class="container-fluid registration"&gt;
      &lt;div class="row"&gt;
          &lt;div class="login-screen"&gt;
              &lt;div class="login-part"&gt;
                  &lt;div class="login-ico col-md-1 col-sm-2 col-xs-12 col-md-offset-3"&gt;
                      &lt;h4&gt;
                          &lt;small&gt;&lt;fmt:message key="registration.label"/&gt;&lt;/small&gt;
                      &lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;div class="login-form col-md-4 col-sm-8 col-xs-12 col-md-offset-1 col-sm-offset-1"&gt;
                      &lt;form action="/registration" enctype="multipart/form-data" method="post"&gt;
                          &lt;%-- error messages --%&gt;
                          &lt;div class="form-group"&gt;
                              &lt;c:forEach items="${registrationErrors}" var="error"&gt;
                                  &lt;p class="error"&gt;${error}&lt;/p&gt;
                              &lt;/c:forEach&gt;
                          &lt;/div&gt;
                          &lt;%-- input fields --%&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input class="form-control" placeholder="&lt;fmt:message key="employee.firstName"/&gt;" name="first_name" required
                                     id="first-name"/&gt;
                              &lt;label class="login-field-icon fui-user"&gt;&lt;/label&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input class="form-control" placeholder="&lt;fmt:message key="employee.lastName"/&gt;" name="last_name" required
                                     id="last-name"/&gt;
                              &lt;label class="login-field-icon fui-user"&gt;&lt;/label&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;span class="input-group-btn"&gt;
                                      &lt;span class="btn btn-primary btn-file"&gt;
                                      &lt;fmt:message key="button.browse"/&gt;
                                      &lt;input type="file" name="userImage" accept="image/*"/&gt;
                                      &lt;/span&gt;
                                  &lt;/span&gt;
                                  &lt;input type="text" class="form-control" readonly=""&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input class="form-control" type="email" placeholder="&lt;fmt:message key="login.email"/&gt;" name="email"
                                     pattern="[^ @]*@[^ @]*\.[^ @]{2,}" required id="email"/&gt;
                              &lt;label class="login-field-icon fui-mail"&gt;&lt;/label&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input class="form-control" type="password" placeholder="&lt;fmt:message key="employee.password"/&gt;" name="password" required
                                     id="password"/&gt;
                              &lt;label class="login-field-icon fui-lock"&gt;&lt;/label&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;input class="form-control" type="text" placeholder="&lt;fmt:message key="employee.position"/&gt;" name="position" required
                                     id="position"/&gt;
                              &lt;label class="login-field-icon fui-plus"&gt;&lt;/label&gt;
                          &lt;/div&gt;
                          &lt;div class="form-group"&gt;
                              &lt;button class="btn btn-primary btn-lg btn-block" name="submit"
                                      type="submit" value="Submit"&gt;
                                  &lt;fmt:message key="button.submit"/&gt;
                              &lt;/button&gt;
                              &lt;a class="login-link" href="&lt;c:url value="/login"/&gt;"&gt;&lt;fmt:message key="registration.login"/&gt;&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/form&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;jsp:include page="parts/scripts.jsp"/&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><code>RegistrationServlet</code>:</p>
  
  <pre><code>@WebServlet("/registration")
  public class RegistrationServlet extends HttpServlet {
      private static Logger log = Logger.getLogger(RegistrationServlet.class);
      private EmployeeService employeeService = new EmployeeService();
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response) {
          try {
              request.getRequestDispatcher("/pages/registration.jsp").forward(request, response);
          } catch (ServletException | IOException e) {
              log.error(e);
          }
      }
  
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response) {
          try {
              request.setCharacterEncoding("UTF-8");
              processRegistration(request, response);
          } catch (ServletException | IOException e) {
              log.error(e);
              e.printStackTrace();
          }
      }
  
      private void processRegistration(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
          String firstName = request.getParameter("first_name");
          String lastName = request.getParameter("last_name");
          String email = request.getParameter("email");
          String password = request.getParameter("password");
          String imageName = "default.png";
          String position = request.getParameter("position");
  
          System.out.printf("Request fields: %s %s %s %s %s%n", firstName, lastName, email, password, position);
  
          Part filePart = request.getPart("userImage");
          try {
              String contentType = filePart.getContentType();
              if (contentType.startsWith("image")) {
                  File image = FileUploadUtils.uploadFile(this, "img\\employees", filePart);
                  imageName = FileUploadUtils.getFilename(image);
              }
          } catch (Exception e) {
              log.error(e);
          }
  
          List&lt;String&gt; registrationErrors = validateInputs(firstName, lastName, email, password, position);
  
          if (registrationErrors.size() &gt; 0) {
              request.setAttribute("registrationErrors", registrationErrors);
              request.getRequestDispatcher("/pages/registration.jsp").forward(request, response);
          } else {
              Employee employee = new Employee();
              employee.setFirstName(firstName);
              employee.setLastName(lastName);
              employee.setEmail(email);
              employee.setEncryptedPassword(password);
              employee.setImage(imageName);
              employee.setPosition(position);
  
              employeeService.save(employee);
              response.sendRedirect("/login");
          }
  
      }
  
      private List&lt;String&gt; validateInputs(String firstName, String lastName, String email, String password, String position) {
          List&lt;String&gt; registrationErrors = new ArrayList&lt;&gt;();
  
          if (ValidationUtils.isNullOrEmpty(firstName)) {
              registrationErrors.add(ValidationErrors.FIRST_NAME);
          }
          if (ValidationUtils.isNullOrEmpty(lastName)) {
              registrationErrors.add(ValidationErrors.LAST_NAME);
          }
          if (!ValidationUtils.isEmailValid(email)) {
              registrationErrors.add(ValidationErrors.EMAIL);
          }
          if (employeeService.getByEmail(email).getId() != 0) {
              registrationErrors.add(ValidationErrors.EMAIL_ALREADY_PRESENT);
          }
          if (ValidationUtils.isNullOrEmpty(password)) {
              registrationErrors.add(ValidationErrors.PASSWORD);
          }
          if (!ValidationUtils.isNullOrEmpty(position)) {
              registrationErrors.add(ValidationErrors.POSITION_EMPTY);
          }
          return registrationErrors;
      }
  }
  </code></pre>
  
  <p>It couldn't extract from request parameters. From my easy checking it prints:</p>
  
  <blockquote>
    <p>Request fields: null null null null null</p>
  </blockquote>
  
  <p>I couldn't figure out why this happen? </p>
  
  <p>Any suggestions?</p>