• Register
0 votes
315 views

Problem :

I am trying to run my registration jsp page with the servlet. But it is throwing following error:

The server encountered an internal error that prevented it from fulfilling this request.

java.lang.NullPointerException

com.java.task11.utils.ValidateUtil.EmailVal(ValidateUtil.java:44)
com.java.task11.webapp.RegistrServlet.validateInputs(RegistrServlet.java:105)
com.java.task11.webapp. RegistrServlet.processRegistration(RegistrServlet.java:77)
com.java.task11.webapp. RegistrServlet.doPost(RegistrServlet.java:49)
javax.servlet.http.HttpServlet.service(HttpServlet.java:700)
javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:62)

I am unable to figure out why this is happening?

Any clues?

7.5k points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

Please find the solution for your error as follows:

if (ValidateUtil.isNullOrEmpty(lastName)) {
registrationErrors.add(ValidateErrors.LAST_NAME);
 }
if (!ValidateUtil.isEmailValid(email)) {
registrationErrors.add(ValidateErrors.EMAIL);
}

I have gone through your problem in above code snippet you are checking for null or empty value on only lastname, but not on isEmailValid for empty value. So you will need something like below code change that will help you.

if (ValidateUtil.isNullOrEmpty(email) || ! ValidateUtil.isEmailValid(email)) {
registrationErrors.add(ValidateErrors.EMAIL);
}

OR

you can fix your ValidateUtil.isEmailValid() to just cope up with the null email values. It will not crash but it will only return false.

OR

There is one more way to fix your issue.

It will work when you will throw away next line from your form:

enctype="multipart/form-data"

And you will pass all parameters at the request ok:

 <form action="/registrationform" method="post">
   <%-- error messages --%>
   <div class="form-group">
    <c:forEach items="${registrationError}" var="error">
    <p class="error">${error}</p>
     </c:forEach>
   </div>
38.6k points