• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can not get context attribute

 
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I am very new to Servlets. Please help.



Here I take the attribute from the field,
set it as an attribute of ServletContext.
The next page of my application tries to retrive this attribute as :



When I execute this there is no error but the value which is printed is null. I don't get it.
I want to take the value from the textfield itself.

The code works well when I set the attribute as



and the value is displayed.

Where am I wrong?



 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your first servlet you are creating the form and trying to get the value of a form field before it has even been sent to the browser. How is the user supposed to fill in the field?

You should be trying to obtain the value of the form field in the servlet that is the result of submitting the form after it has been displayed in the browser.
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I want the value from the field of that page.
I want to set the value,which I received from the field,as context attribute and want to retrieve that value in the next page and display it.

I too got a hint about this problem but could not come up with an idea how to solve this silly problem.
Sorry to waste your time,but can you suggest my something about what I want to do?


 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:


You should be trying to obtain the value of the form field in the servlet that is the result of submitting the form after it has been displayed in the browser.



I did not get it clearly.
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I got what you say.
But my query is cant I set the context attribute with the retrieved value?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can't retrieve the value until it's submitted. Simply writing the form to the response doesn't create the form. The response must be sent to the browser, and then when the user submits the form, you can retrieve the value in another servlet that's invoked as the action of the form.
 
sudipto shekhar
Ranch Hand
Posts: 826
Eclipse IDE Oracle Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you.
I got that.

 
Surfs up space ponies, I'm making gravy without this lumpy, tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic