Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can not get context attribute

 
sudipto shekhar
Ranch Hand
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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?



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65223
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you.
I got that.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic