aspose file tools*
The moose likes JSP and the fly likes Problem while trying to retreive values doPost 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 » JSP
Bookmark "Problem while trying to retreive values doPost " Watch "Problem while trying to retreive values doPost " New topic
Author

Problem while trying to retreive values doPost

Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Folks ,
Im trying to write a web app. I face an issue while trying ot retreive a value that I've set in the request scope of the variable in my jsp as below


I set the value for the variable in the doGet method of my servlet.


However, when i try to access this value in the doPost mehod of my servlet after the page submits , it always shows up as null

Any clue as to where I could be going wrong?
Thanks a lot.

Learning and Learning!-- Java all the way!
Ravi Sree
Ranch Hand

Joined: Jan 24, 2010
Posts: 64

Hi,

First of all,
The methods doGet and doPost should be like:

&

Also,
when is this 'issue' that you see?
where are you setting this value in your jsp for posting to your servlet?

Regards,
Sree
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Hi Ravi!
Thanks for replying ! I tried changing the return type from protected to public , yet no use.
The issue that I face , as explained before occurs when I try to store a value that I obtain from my do Get method in the jsp using c:set which works well .But when i try to get back the value in the do Post method using request .getParameter it throws a null. Hope im being clear
Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Once the response is sent to the browser, the request is complete. So when the page is subsequently submitted, it creates a new request. Any scoped variable created in the first will, of course, not be available in the second. Why would you think it would be?

And what is the purpose of the following statement?
<c:set value="${consumer_id}" var="consumer_id" scope="request"/>

This does nothing. Why is it in your page?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Bear Bibeault wrote:Once the response is sent to the browser, the request is complete. So when the page is subsequently submitted, it creates a new request. Any scoped variable created in the first will, of course, not be available in the second. Why would you think it would be?

And what is the purpose of the following statement?
<c:set value="${consumer_id}" var="consumer_id" scope="request"/>

This does nothing. Why is it in your page?


Hi Bear,
Thanks for replying. I dont know whether my approach is right here .But here's what Im trying to do ..
Consider Im using 2 jsp's A and B with servlets A1 and B1 respectively
The value of "consumer_id" is actually being fetched from jsp A which points to servlet B through a link.
I get the value of consumer id in servlet B's doGet method using request.getParameter .
Now I want this value of "consumer_id" to be available for processing in the doPost method of servlet B, when i submit the jsp B and hence i try and set it in a variable using c:set in jsp B, but that approach doesn't seem to be working..
Any clue on what I could be doing wrong here?
Thanks.


through page which redirects to the
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Using your <c:set> is not going to do anything for you. The way you coded it, it's just setting a scoped variable to its own value. Of what use is that? And as the scoped variable doesn't exist in the first place in the request, it's certainly not going to do anything useful at all.

Think! Stop, and think!

If you set a scoped variable into the request, how is that going to be helpful in obtaining the value in a completely different request?

The answer is, of course, that it's not.

So where might you store the data such that it will be available in a subsequent request?
Vic Hood
Ranch Hand

Joined: Jan 05, 2011
Posts: 477

Session?? Unless im not mistaken again ...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Ravi Sree
Ranch Hand

Joined: Jan 24, 2010
Posts: 64

If you are sure you still want to use the variable in request scope,

&
and get this property where you want next,
Also before submitting make sure you are using the correct form method.

Regards,
Sree
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61417
    
  67

Messy. The session is much cleaner.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem while trying to retreive values doPost