• Post Reply Bookmark Topic Watch Topic
  • New Topic

What does this do? request.getParameter("string" + int)

 
Daniah Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you fix this please only do the string math once.
 
Daniah Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I will do the error checking and the string math one time and post the results.
 
Daniah Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Saifuddin Merchant
Ranch Hand
Posts: 607
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

HTH!
 
Daniah Thomas
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds very possible. I will check this with Firebug and post the result. Thank you.
 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would recommend you to check the value of "num". I suspect scriplets are doing some processing on num.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65520
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!