aspose file tools*
The moose likes Servlets and the fly likes doPost in servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "doPost in servlets" Watch "doPost in servlets" New topic
Author

doPost in servlets

anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
I am using the hidden fields to pass the information from one page to other.
I can use doGet or do post. but if i use doget then the field info is dispalyed on the address bar and user can change it and get the diffent data.
So I have to go for doPost.
Is to advisable to use doPost for all my pages. ??
or do i have any other option.
If i have a link in my page then also i need to call a javascript and post my form to the next page.
But with do post there is a problem, i cant use no-cache as when i click the browser back button then it asks for the refresh option.
Regards
Anil
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Anil
Why are you using hidden form fields and not session objects? then you eliminate the problem of them seeing the values in the location bar and the problem of having to control all of the values through javascript.
Is to advisable to use doPost for all my pages. ??
As far as I know there is no performance difference between post and get. IF you are going to use one or the other, in my mind, it is better to be consistent and use the same one all the time. The other option available is that you can have a single page call the same servlet but access either the doPost or the doGet method depending on how the form is submitted.
But with do post there is a problem, i cant use no-cache as when i click the browser back button then it asks for the refresh option.
that is intentional so that if you post say, a credit card form, the location can not be stored in the users browser accidentally and then submitted again later in error.


Dave
anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
hi Dave
why i am not using session variable is because..
I have to link an account with a customer
So i search for a account- search for a customer
display both the details side by side in the link screen (acc1, cust1). When i click on "link" these two are linked.
so till this point the account and customers are in my session
now suppose before clicking "link" the user goes back to search the account and customer (This is not by clicking the browser back but by the navigation link which is to be provided on the top of the page)
So again after searching for the account and the customer, he comes to the link page (again acc2 and cust2 are in my session). But again the user thinks somthing and using the browser back button he goes back the the previous link screen where he is shown the acc1 and cust 1 details and he says "link".
He sits happily thinking he has linked acc1 and cust 1 but when he get compalins that the account is not linked he is confused, checks in the database then he finds that acc1 and cust 1 are not linked instead acc2 and cust 2 are linked as these were the data in the session when he pressed "link".
So i feel i have only the option of using doPost, or doGet. With doGet having the details on the address bar its better to use doPost ???
regards,
Anil
Zakaria Haque
Ranch Hand

Joined: Jan 02, 2002
Posts: 60
you can use a different encoding for the hidden fields. Simply using a base64 encoding may suffice for typical users.
Or you can put a key in the hidden fields and use that key to retrive different set of values from session.


tobe bondhu nouka bherao<br />shonabo gaan aj shara raat
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12683
    
    5
I think part of the problem is that when some screens are generated, you don't know what the user has been doing.
You could record state information in the session, making an entry for each page displayed.
When making a new page, you could make a decision based on the history. You could even display the user's history (possibly a "breadcrumbs" like display?)
There is a design pattern called (I think) the command pattern where the state information saved is enough to roll back (undo) the actions so as to arrive at an earlier condition.
It is an interesting problem - let us know how you solve it....
Bill


Java Resources at www.wbrogden.com
anil bisht
Ranch Hand

Joined: Nov 04, 2000
Posts: 81
hi zakaria
you can use a different encoding for the hidden fields. Simply using a base64 encoding may suffice for typical users.
How can i do this ??
Or you can put a key in the hidden fields and use that key to retrive different set of values from session.
using this i suppose i would overload the session. As i have to put all the visited page values into the session..
Regards
Anil
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12683
    
    5
Don't worry about "overloading" a session, there is no limit except available memory on session contents, and if all the contents are serializable, some servlet engines will store sessions to disk. Naturally good design would require cleaning up all the stored objects when they are not needed anymore.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doPost in servlets
 
Similar Threads
overridding service()
doGet(), doPost() implementation
please reply urgently!!!
Which Method Process Forward
doPost vs doGet