Preface
Before browsing this article, make sure you are experiencing similar problems under similar environment and condition below.
Environment:
Os:windows XP
Language:java 1.5
Framework:struts 1.3
Ide:myeclipse 6.0
Condition:
In the JSP page normal, object class is used in Actionform.
Introduction
This article describes the exception that can be caused when you use object class in Actionform.
Section1-problem HTTP Status-
type Exception
Message
Description The server encountered an internal error () is prevented it from fulfilling this request.
Exception
Org.apache.jasper.JasperException:javax.servlet.ServletException:javax.servlet.jsp.JspException:Getter for Property Countryregioncode threw Exception:java.lang.NullPointerException
Org.apache.jasper.servlet.JspServletWrapper.handleJspException (jspservletwrapper.java:541)
Org.apache.jasper.servlet.JspServletWrapper.service (jspservletwrapper.java:417)
Org.apache.jasper.servlet.JspServlet.serviceJspFile (jspservlet.java:320)
Org.apache.jasper.servlet.JspServlet.service (jspservlet.java:266)
Javax.servlet.http.HttpServlet.service ( httpservlet.java:803)
root Cause
Javax.servlet.ServletException:javax.servlet.jsp.JspException:Getter for property Countryregioncode threw exception : Java.lang.NullPointerException
org.apache.jasper.runtime.PageContextImpl.doHandlePageException ( pagecontextimpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException ( pagecontextimpl.java:779)
Org.apache.jsp.fundinformation.fundhousesearch_jsp._jspservice (FundHouseSearch_ jsp.java:365)
Org.apache.jasper.runtime.HttpJspBase.service (httpjspbase.java:70)
Javax.servlet.http.HttpServlet.service (httpservlet.java:803)
Org.apache.jasper.servlet.JspServletWrapper.service (jspservletwrapper.java:393)
Org.apache.jasper.servlet.JspServlet.serviceJspFile (jspservlet.java:320)
Org.apache.jasper.servlet.JspServlet.service (jspservlet.java:266)
Javax.servlet.http.HttpServlet.service ( httpservlet.java:803)
root Cause
Javax.servlet.jsp.JspException:Getter for property Countryregioncode threw Exception:java.lang.NullPointerException
org.apache.struts.taglib.html.SelectTag.calculateMatchValues (selecttag.java:245)
Org.apache.struts.taglib.html.SelectTag.doStartTag (selecttag.java:177)
ORG.APACHE.JSP.FUNDINFORMATION.FUNDHOUSESEARCH_JSP._JSPX_METH_HTML_005FSELECT_005F0 (FundHouseSearch_jsp.java : 487)
Org.apache.jsp.fundinformation.fundhousesearch_jsp._jspservice (fundhousesearch_jsp.java:197)
Org.apache.jasper.runtime.HttpJspBase.service (httpjspbase.java:70)
Javax.servlet.http.HttpServlet.service ( httpservlet.java:803)
Org.apache.jasper.servlet.JspServletWrapper.service (jspservletwrapper.java:393)
Org.apache.jasper.servlet.JspServlet.serviceJspFile (jspservlet.java:320)
Org.apache.jasper.servlet.JspServlet.service (jspservlet.java:266)
Javax.servlet.http.HttpServlet.service ( httpservlet.java:803)
Note The full stack trace's the root cause is available in the Apache tomcat/6.0.13 logs. Apache tomcat/6.0.13
Section 2-reason
For example, there is a property on the JSP page first
Actionform with its default is no problem, but from the reuse and abstract aspect point of view, generally define in the actionform of the private property are only in the JSP Page has this property and the actual object class does not have the property, or the property needs to be converted by action to the object class. So when the property on the JSP page corresponds to the property of the actual object class, the property on the JSP page is no longer define a new property on the Actionform. Instead, you manipulate the property by getter and setter on Call object class, but it is often easy to make an error because you have to actionform a new object in the Class of instance, if not new to meet the above exception, such as code:
Actionform:
/** Fundhouse Property * *
Private Fundhouse Fundhouse;
/** Fundhousename Property * *
Private String Fundhouseid;
/**
* @return The Fundhouse
*/
Public Fundhouse Getfundhouse () {
return fundhouse;
}
/**
* @param fundhouse the Fundhouse to set
*/
public void Setfundhouse (Fundhouse fundhouse) {
This.fundhouse = Fundhouse;
}
/**
* @return The Fundhouseid
*/
Public String Getfundhouseid () {
return Fundhouseid;
}
/**
* @param fundhouseid the Fundhouseid to set
*/
public void Setfundhouseid (String fundhouseid) {
This.fundhouseid = Fundhouseid;
}
Object Class:
Private String Fundhouseid;
/**
* @return The Fundhouseid
*/
Public String Getfundhouseid () {
return Fundhouseid;
}
/**
* @param fundhouseid the Fundhouseid to set
*/
public void Setfundhouseid (String fundhouseid) {
This.fundhouseid = Fundhouseid;
}
Section 3-solution
Very simple, but very easy to be ignored, must be new an object class instance, the above Actionfrom Fundhouse property modified as follows:
Private Fundhouse Fundhouse = new Fundhouse ();