0
votes

I am using bean to validate the form of JSP. If use setProperty and if some fields on the form is left blank it is throwing a null pointer exception. This exception is happening only if the field is happen to be numbers in the bean. I cant do validation without calling setProperty of bean. Is there any other way to do this ? The code i am using is as follows.

<jsp:useBean id="addBean" scope="request" class="org.mypackage.products.add_product6_Variables" />
    <jsp:setProperty name="addBean" property="*" />

My Error:

org.apache.jasper.JasperException: An exception occurred processing JSP page /response.jsp at line 19

19: jsp:setProperty name="addBean" property="*" />

type Exception report

message 

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

exception 

org.apache.jasper.JasperException: org.apache.jasper.JasperException: org.apache.jasper.JasperException: error in invoking method
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:500)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

org.apache.jasper.JasperException: org.apache.jasper.JasperException: error in invoking method
    org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:361)
    org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:308)
    org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:286)
    org.apache.jsp.response_jsp._jspService(response_jsp.java:77)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

org.apache.jasper.JasperException: error in invoking method
    org.apache.jasper.runtime.JspRuntimeLibrary.createTypedArray(JspRuntimeLibrary.java:533)
    org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:350)
    org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:308)
    org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:286)
    org.apache.jsp.response_jsp._jspService(response_jsp.java:77)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


root cause 

java.lang.NumberFormatException: empty String
    sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
    java.lang.Float.valueOf(Float.java:388)
    org.apache.jasper.runtime.JspRuntimeLibrary.createTypedArray(JspRuntimeLibrary.java:516)
    org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:350)
    org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:308)
    org.apache.jasper.runtime.JspRuntimeLibrary.introspect(JspRuntimeLibrary.java:286)
    org.apache.jsp.response_jsp._jspService(response_jsp.java:77)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


1

1 Answers

2
votes

Is your bean property type a primitive number or the wrapped object type? I mean int or Integer?

It probably is of type int now since int and other primitives cannot be set to null; while an Integer object can be set to null.

Can you change your bean property type to Integer etc and check whether the NPE still exists?