• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

doPost in servlets

 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
anil bisht
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
anil bisht
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic