• Post Reply Bookmark Topic Watch Topic
  • New Topic

req.getParameter("");

 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get the subject that is: "10.5% decline in the sale"
The percent(%) sign is creating problem and the program throws NullPointerException

String subject=req.getParameter("subject");
I tried URLEncoder.encode(subject,"UTF-8") but still the same error

How can I get rid of this % sign

thanks & best regards
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to URL-encode the data. Since URL-encoding uses the '%' character to escape data, it shows why you are getting errors.

The '%' character is ASCII code 37, which is hexideciaml 25, therefore you should write 10%2E5%25
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:
You need to URL-encode the data. Since URL-encoding uses the '%' character to escape data, it shows why you are getting errors.

The '%' character is ASCII code 37, which is hexideciaml 25, therefore you should write 10%2E5%25


Thanks for your reply and guidance

I still need some more help in this regard. Can you please get me an example?

thanks again & best regards
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did, can you be more specific?
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:
I did, can you be more specific?


subject="Sale is going down by 10.25%";
String subject=req.getParameter("subject");
out.prinln(subject);

Can you please correct my code?

thanks again
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have your URL something like:


Though it is not a great idea of having your request params named in such a way. Better to give them a small meaningful name without special characters. If you have some specific requirement to name it this way, please share it.
[ August 25, 2008: Message edited by: Satya Maheshwari ]
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satya Maheshwari:
You can have your URL something like:


Though it is not a great idea of having your request params named in such a way. Better to give them a small meaningful name without special characters. If you have some specific requirement to name it this way, please share it.

[ August 25, 2008: Message edited by: Satya Maheshwari ]

Thanks Satya for your reply but I don't think its a good solution. I don't what the user will insert as input but I am trying to control the input that if the user is using % sign then what should I do?

David O: has given a good advice but due to lack of my knowledge I am unable to implement it in my code.

I again request help if possible

Thanks again
 
Soniya Ahuja
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
It should be treated as a string.
Now could you please tell me how are you trying to set this parameter. If it is being set in a program and is then forwarded to a servlet or jsp - please use setAttribute and then use getAttribute to use it.

You can use parameters with JSPs or html for user input or directly send it with the url

this is what I get when i use form parameters

http://localhost:8080/SCWCD/testing1.do?username=Soniya+50%

Soniya 50% is what i typed in the text box.

When I tried to print it using request.getParameter("username");
it returned Soniya 50%.

Since you are getting a null pointer exception, it means that there is no data and not that data is not being passed correctly.

Please specify how you are setting your parameters if you want more clarification
[ August 26, 2008: Message edited by: Soniya Ahuja ]
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Satya for your reply but I don't think its a good solution. I don't what the user will insert as input but I am trying to control the input that if the user is using % sign then what should I do?


Sorry, I got your question wrong,from your code I thought, the param name is "Sale is going down by 10.25%" and not the value.
Anyway, what is preventing you from using a POST to your servlet? The request params would not be passed through the URL then.
[ August 25, 2008: Message edited by: Satya Maheshwari ]
 
Mark Williams
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Farakh khan:


subject="Sale is going down by 10.25%";
String subject=req.getParameter("subject");
out.prinln(subject);

Can you please correct my code?

thanks again


Are you sure that the parameter is really getting passed to the servlet? To me it sounds like there is no parameter named subject in the request at all. If the % was causing problems, I don't think subject would point to null...
 
Farakh khan
Ranch Hand
Posts: 833
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Williams:


Are you sure that the parameter is really getting passed to the servlet? To me it sounds like there is no parameter named subject in the request at all. If the % was causing problems, I don't think subject would point to null...


I checked numerous time when am writing % sign then its not getting parameter but without % sign its getting parameter

best regards
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!