What does this do? request.getParameter("string" + int)
Daniah Thomas
Greenhorn
Joined: Jul 14, 2009
Posts: 4
posted
0
I assume that it is supposed to append the integer to the end of the string, but I do not believe this assumption is correct. The following is the code:
num is an integer passed in from another method and Sic is a string. My error is Exeception: java.lang.NullPointerException. From my log, I discovered that the furthest it got was line 280. I have tried to cast num using String.valueOf() and I have also tried to cast "Sic" for the if statement. Once cast, code is set to the value of Sic with the number appended. Once I ran the program, this implementation is incorrect. So my question is, What does this do?
Gets whatever parameter is named using the string passed in.
The NPE will occur if such a parameter does not exist as null will be returned. The code is sloppy and needs to check for existence of the value before trying to trim it.
As you fix this please only do the string math once.
Daniah Thomas
Greenhorn
Joined: Jul 14, 2009
Posts: 4
posted
0
Thank you. I will do the error checking and the string math one time and post the results.
Daniah Thomas
Greenhorn
Joined: Jul 14, 2009
Posts: 4
posted
0
So I did the error checking and it did get rid of the exception, but that field in the form isn't supposed to be null. When it is, an error message comes up on the screen. But after the error checking, even when the field isn't empty, the error message shows up on the screen.
My job is revamping code from about 7 years ago, and we are in the process of taking scriptlets out of the jsps. The jsp that accompanies this servlet is scriptlet free, and now I am having trouble with this servlet. Before I took the scriptlets out, this portion of the program worked... But because we have upgraded WAS, the scriptlets must go and now this portion fails.
Could someone explain to me how this is happening? Before I took out the scriptlets, there was a value for request.getParameter("string" + int), but after the scriptlets are gone, no value for request.getParameter("string" + int). The same information is being entered on the screen as it was before.
You need to check what you are passing back to the server. Most likely the change to remove the scriptlets you might have missed something and are not passing the parameters to the server.
You might want to check what you are passing back to the server using Firebug in case you can use Firefox or the IE Developer Toolbar
shivendra tripathi wrote: I would recommend you to check the value of "num". I suspect scriplets are doing some processing on num.
How this be possible in a page with no scriptlets?
shivendra tripathi
Ranch Hand
Joined: Aug 26, 2008
Posts: 263
posted
0
Since earlier he has scriplet in page which might be doing some processing so he was able to get the param value.
for ex
num = num+1;
request.getParameter(String + num);
now since he has removed the scriptlet so he is trying to find different param value which doesn't exist.