| Author |
Can not get context attribute
|
sudipto shekhar
Ranch Hand
Joined: Apr 02, 2008
Posts: 813
|
|
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?
|
Regards, Sud.
SCJP 5 ScjpFAQ JLS
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56531
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
sudipto shekhar
Ranch Hand
Joined: Apr 02, 2008
Posts: 813
|
|
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
Joined: Apr 02, 2008
Posts: 813
|
|
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
Joined: Apr 02, 2008
Posts: 813
|
|
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
Joined: Jan 10, 2002
Posts: 56531
|
|
|
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
Joined: Apr 02, 2008
Posts: 813
|
|
Thank you. I got that.
|
 |
 |
|
|
subject: Can not get context attribute
|
|
|