Values showing up as null in expression

I have a page that allows the user to modify some info in 2 fields and after making the change the info then gets sent to a servlet that makes the update. Problem is that before it's sent to the servlet the parameters show up as null. It's an object that is retrieved when the page first loads (I check to make sure it's not null obviously) then I use the object (through basic getter methods) to retrieve the data for the fields. after clicking the button I get the following error message:

java.lang.NullPointerException

at org.apache.jsp.modQuestion_jsp._jspService(modQuestion_jsp.java:125)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)

....and it just keeps going. org.apache.jsp.modQuestion_jsp._jspService(modQuestion_jsp.java:125 is the line where I access the data to set it in the field. I'm able to set the value for the fields (one is actually a textarea and the other just an input field) when the page loads but when I send the data to the servlet I get this error. I can see the data just fine. The really strange part is that I do the exact same thing in another part of the app and I have no problem there. Has anyone had this problem before 'cause man am I stupped. Thanks

[1636 byte] By [uberallesa] at [2007-11-26 22:45:55]
# 1
You keep talking about a servlet, but that stack trace comes from a JSP. What is the relationship between the two?And you don't post any code from either the servlet or the JSP. That makes it very hard for us to say anything more useful than "You aren't doing it right".
DrClapa at 2007-7-10 12:03:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

I did mention that the problem occurs before anything gets sent to the servlet. The relationship is a simple one: read in several parameters and then update the db. Since the problem has nothing to do with the servlet...here is the problem area of the jsp:

******

<form action="servlet/SingleQuestion/" method="post">

<div style="float:left;margin-left:2%;width: 33%;">

Question

<textarea name="ques" COLS=30 ROWS=6>

<%=sq.getQuestion()%>

</textarea>

</div>

<div style="float:right;margin-right:5%;width: 33%;">

Amount

$<input type="text" name="am" value= <%=sq.getAmount()%> size=3>

This question has been marked as too low <font color="red"><%=sq.getLowCount()%></font> time(s)

</div>

<div style="float:left;margin-left:25%;margin-top:4%; width: 50%;">

<input type="submit" value="Enter">

</div>

<input type="hidden" name="type" value="mod">

<input type="hidden" name="id" value=<%=sq.getID()%>>

</form>

************

I discovered something though. If I remove the hidden fields then it works fine. Any reason? Thanks again.

uberallesa at 2007-7-10 12:03:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
I don't know if you solved this, but check in your Tomcat's log files it will have full stack trace of the error you are facing.Post the full stack trace here.
appy77a at 2007-7-10 12:03:41 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Here's the full stack trace:

org.apache.jasper.JasperException

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:207)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)

at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)

at java.lang.Thread.run(Thread.java:534)

-- Root Cause --

java.lang.NullPointerException

at org.apache.jsp.modQuestion_jsp._jspService(modQuestion_jsp.java:125)

at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:92)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)

at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:162)

at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)

at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:144)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2358)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:133)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)

at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:118)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:116)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:594)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:127)

at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)

at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)

at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:948)

at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:152)

at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)

at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)

at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)

at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)

at java.lang.Thread.run(Thread.java:534)

I've already posted the jsp code in question.Thanks again.

uberallesa at 2007-7-10 12:03:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

According to the stack trace you're getting a NullPointerException in the JSP file.

The above exception can occur if one is trying to invoke a method on an object that is already null , for example - if the object sq itself is null then calling sq.getID() , is like calling a method on a null object and it gives Null Pointer Exception.

So to solve this particular problem in your JSP , print the value of each object that you suspect to be null if the object prints as null - then there you have your answer , for example:

<%

String something = null;

%>

This is soemthing object: <%=something%>

in case of the above code your output will be:

This is soemthing object: null

> <input type="hidden" name="type" value="mod">

> <input type="hidden" name="id"

> value=<%=sq.getID()%>>

> </form>

> ************

> I discovered something though. If I remove the hidden

> fields then it works fine. Any reason? Thanks again.

HTH

appy77a at 2007-7-10 12:03:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Yeah I tried it that way as well. The weird thing is that the data in the object shows up at first (the fields on the page are populated just fine) it's when that data is passed to the servlet that it comes up null. I don't understand how the data is there one second and then gone the next when really nothing changes. I do have another option as a solution but I still find this whole 'bug' very odd. Thanks for the help nonetheless.

uberallesa at 2007-7-10 12:03:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

> Yeah I tried it that way as well. The weird thing is

> that the data in the object shows up at first (the

> fields on the page are populated just fine) it's when

> that data is passed to the servlet that it comes up

> null.

Is this the correct URL path for the Servlet?

servlet/SingleQuestion/

Typically Servlets are defined in /WEB-INF/web.xml and the URL pattern looks something like <url-pattern>/SomeServlet</url-pattern>

so if the pattern is as defined above then the Servlet should begin with a /

so in the form's action it would be form action="/SomeServlet"

> I don't understand how the data is there one

> second and then gone the next when really nothing

> changes. I do have another option as a solution but I

> still find this whole 'bug' very odd.

How are you accessing the data in the Servlet, are you using request.getParameter , or are you getting it via session ?

> Thanks for the

> help nonetheless.

You're welcome.

appy77a at 2007-7-10 12:03:42 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...