Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

request.getParameter() from same page as HTML FORM

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jsp page with a form. form contains a textfield, once the user submits the form, i want jsp scriptlet to get the value of the user input and carry out processing on it within the same page and give a result.
problem is the first time the page is loaded, there is an error in the request.getParameter() statement since no form has yet been submitted i guess ....
if i use another page ... it works ... but i want to display the information in the same page ...
thanks
 
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't you check the parameter for null and spaces first.
if(request.getParameter("yourParameter") != null && !request.getParameter("yourParameter").equals(""))
do whatever...
 
Ranch Hand
Posts: 897
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I found that this bit of code works (see example below).
Let us know how you get on.
Cheers!
Mark
 
sarim raza
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANKS A LOT !!!
thanks mark and bosun ..
Mark your code works, you guys are experts as usual ... I remember from my time here when preparting for SCJP2 !!
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai,


According to your program,once we submit the data ,the value in the text field is disappering.how to keep this value as such even after submission of the data.

Regards
Babu
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by yoga babu:


the value in the text field is disappering.how to keep this value as such even after submission of the data.



Hi Babu,

hope you will get your solution here.. you just need to do that to bind your string variable with value in textfield by checking null like what Bosun Bello did for you in above code..

your code would be like this..



hope this helps..
[ December 14, 2006: Message edited by: Saif uddin ]
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sarim,

You can use this also

if (request.getParameter("Submit")!=null) so that your page does not show any error for the first time
 
Muhammad Saifuddin
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dhanya Palanisamy:
Hi Sarim,

You can use this also

if (request.getParameter("Submit")!=null) so that your page does not show any error for the first time



Why you check the submit value ?

I think we don't need to check the Button value in this condition. The error will not occur on the submit(button) value because i retrieved textField value in request.getParameter("MyText") so i already applied that (if condition) in above post to checking the null value.. for the first time loading.
 
Dhanya Palanisamy
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Saif,

if (request.getParameter("Submit") != null) makes sure the page has already been submitted. So placing getParameter() for other fields inside this condition will not give you any errors before the page is submitted.

If you have one or two fields you can check for null values as you suggested but it will be difficult if you have more fields.

Hope i explained properly.
 
yoga babu
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Bear edit: thread hi-jack removed. Please start your own questions in a new topic.]
[ December 15, 2006: Message edited by: Bear Bibeault ]
 
The two armies met. But instead of battle, they decided to eat some pie and contemplate this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic