aspose file tools
The moose likes Servlets and the fly likes What does this do? request.getParameter( Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "What does this do? request.getParameter("string" + int)" Watch "What does this do? request.getParameter("string" + int)" New topic
Author

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

Daniah Thomas
Greenhorn

Joined: Jul 14, 2009
Posts: 4
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

Joined: Jan 10, 2002
Posts: 56168
    
  13

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.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

As you fix this please only do the string math once.
Daniah Thomas
Greenhorn

Joined: Jul 14, 2009
Posts: 4
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
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

Joined: Feb 08, 2009
Posts: 576

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!


Cheers - Sam.
Twisters - The new age Java Quiz || My Blog
Daniah Thomas
Greenhorn

Joined: Jul 14, 2009
Posts: 4
That sounds very possible. I will check this with Firebug and post the result. Thank you.
shivendra tripathi
Ranch Hand

Joined: Aug 26, 2008
Posts: 263
I would recommend you to check the value of "num". I suspect scriplets are doing some processing on num.


SCJP 1.5(97%) My Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56168
    
  13

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
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.
 
I agree. Here's the link: http://jrebel.com/download
 
subject: What does this do? request.getParameter("string" + int)
 
Similar Threads
does excel support utf-8 encoding?
Parsing
OpenCSV Error on server
JasperException: For input string: ""
How to pass a javascript variable on a jsp to a servlet