aspose file tools*
The moose likes Struts and the fly likes NullPointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "NullPointerException " Watch "NullPointerException " New topic
Author

NullPointerException

Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Hi All,

When I try to validate in ActionForm, I get the below message. Could someone advise.

ERROR [http-8080-Processor23] (ApplicationDispatcher.java:704) - Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.pages.user_005fprof_jsp._jspService(user_005fprof_jsp.java:5959)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
at org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1001)
at org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:966)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:204)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)

Could someone tell me the root cuase of the problem. Any more info needed, please let me know.

Thanks,
Ananth
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This exception appears to be getting thrown from the code in a scriptlet within your JSP. Check your code in this JSP and look for situations where you expect an object to have a value but it might unexpectedly be null.

Remember that when struts redisplays a JSP due to validation errors, objects that you might have put in request scope when the page was originally displayed are no longer there. See Question 17 of this forum's FAQ for advice on how to handle this situation.
[ November 14, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Thanks.

I am not using any onsubmit or javascript. It is a simple html:form with action attribute and method="post".

In the form the validation is as below.

if((selectEmail == null) && (email1.trim().equalsIgnoreCase(""))){
errors.add("selectEmail", new ActionMessage("testForm.selectEmail.required"));
}

Please let me know on the validation code. I am checking for the user to select a email from the list or enter one in the text box.

Thanks for the help.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
I tried to post this earlier but I got an error message from the forum...I see that Merrill has posted about the same info already, but maybe this will help. The problem is not with your validation code, it is with your JSP.

Looking at the stack trace, my guess at to what is happening is 1) the validation code is detecting a validation error 2) Struts is forwarding to the input attribute of your action mapping 3) the jsp is throwing a null pointer exception while trying to display the page.

If your input attribute is referencing a jsp file, then I suspect that there are some things you are putting in the form or the request in the action that initially displayed the page and these things are now null. There is a recent FAQ entry that touches on this topic: http://faq.javaranch.com/java/RefreshValuesOnValidationError

- Brent
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Originally posted by Ananth Ram:
I am not using any onsubmit or javascript.

When I used the term "scriptlet" in my post, I was not referring to JavaScript but rather to Java code enclosed within <% %> tags in your JSP.
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Thanks Merrill. Yes, there were some problems with the scriptlets (Java code).

Thanks for the timely help.

Ananth
 
 
subject: NullPointerException