0

I am getting a weird error of page constantly fluctuating between nullpointerexception to actual execution on every form submit. I am writing a simple jsp page and running it on tomcat 5.x server. I am taking data from text field of a form and processing it upon form submit. Here is the code I am trying:

form id="mainForm" method=POST action="index.jsp">

<input type="text" name="reportName" size=20> 



<a class="btnBlue btnBlueRight" href="#" onclick="document.getElementById('mainForm').submit();" > 

            <% 
            if(request.getParameter("reportName")!=null){
            //do things
            else
            //print message
            %>

for this code, page address in address bar is localhost:8080/# or localhost:8080/index.jsp for every form submit. I am new to jsp so could not resolve this.

pbd
  • 423
  • 3
  • 8
  • 19
  • please include the npe (null-pointer exception). – Daniel Moses Jan 03 '13 at 20:59
  • i handled the exception so it just shows java.lang.nullpointerexception – pbd Jan 03 '13 at 21:01
  • **request.getParameter("reportName")** happens on page build, it could be for the submit/query that is building the page the parameter was not sent. If the jsp was invoked directly, for example, there would be no parameters unless specified in the url. – BevynQ Jan 03 '13 at 21:04
  • i get the point that input text is the issue and somehow it is not getting initialized for first form submit, but it works perfectly well if i resubmit the form! – pbd Jan 03 '13 at 21:04
  • there is no npe in the code shown. The exception will have a line number where the npe occurs. if you have code in the `//do things` or `print message` section you might include that and someone can find your NPE for you. – Daniel Moses Jan 03 '13 at 21:04
  • @pbd - that would be my expected behaviour. – BevynQ Jan 03 '13 at 21:06
  • the //print message is message i set up for NPE. So the output is either the //print message (1st form submit) or //do things (on resubmit) – pbd Jan 03 '13 at 21:08
  • @BevynQ- how can i make sure i set these parameters for execution by jsp? – pbd Jan 03 '13 at 21:11
  • It's because the reportName does not set any where for the first time page load! – Yasser Zamani Jan 03 '13 at 21:13
  • @YasserZamani- I did not understand, you mean set it within jsp code? – pbd Jan 03 '13 at 21:16

1 Answers1

1

It's because the reportName does not set any where for the first time page load! e.g. try to navigate

localhost:8080/index.jsp?reportName=all

Yasser Zamani
  • 2,380
  • 21
  • 18