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

How to request..

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet form which contains one textField and a label with name Prompt, When i open the form the prompt displays it's current value, which i am trying to modify(update the current data), in order to this, i need to get the current value from the Prompt and store it in the session, If i do this it does not get updated with the current value, it's always displaying null.
So could anyone please let me know how to get the current data from the prompt field, for which i want to do the validation and update appropriately.
This is what i have in my code.
I have created the session
HttpSession session = req.getSession();
String prompt = getParameter("prompt");
session.putValue("TestForm.Prompt", prompt);
String promptValue = session.getValue("TestForm.Prompt");
Please let me know,
Thanks,
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
set the create variable to true, otherwise if there is no valid session, a null is returned.

Try:
HttpSession session = req.getSession(true);
----
String prompt = getParameter("prompt");
session.putValue("TestForm.Prompt", prompt);
String promptValue = session.getValue("TestForm.Prompt");
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created the seesion by setting it to true, forgot to mention in my code fragment above. It is still returning me null value.
Any further changes do i need to make.
Please let me know.
Thanks,
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although I'm not sure about this one being right either, but you might want to give it a try:
String prompt = req.getParameter("prompt");
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the above the statement which you have mentioned, but still not working.
Any further Suggestions?
Thanks,
 
John Bateman
Ranch Hand
Posts: 320
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post more complete code?
I notice you don't use the request object for your 'getParameter("prompt") and even though you tried using request.getParameter("prompt") I'd like to make sure you're just not missing something else.
Thanks alot.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you, its working fine now. I was clearing of the session, hence it was getting null value.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic