aspose file tools*
The moose likes Servlets and the fly likes Can not get context attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can not get context attribute" Watch "Can not get context attribute" New topic
Author

Can not get context attribute

sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

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: 61420
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sudipto shekhar
Ranch Hand

Joined: Apr 02, 2008
Posts: 823

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: 823

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: 823

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: 61420
    
  67

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: 823

Thank you.
I got that.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can not get context attribute