| RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To |
| ISAPI tutorial for Delphi developers | |||||||||||||||
| Page 10: Overcoming HTTP's Stateless nature | |||||||||||||||
As I mentioned in Page 1, HTTP is a stateless protocol. To overcome this problem we can resort to various methods. The three most common ones are: Cookies, (Fat) URL's., and Hidden Fields.
I will discuss briefly all three methods. Personally I like the use of cookies. I have seen a lot of questions on the newsgroups with a short parenthesis saying "I don't want to use cookies". As I mentioned in the previous chapter, cookies is a very debated issue and I'm not going to add to it. I just think that if they are used in the correct way they can save you a lot of work. However, if you are still against using cookies, I will describe other methods to maintain state information. You can then pick which ever one suites your needs and taste better.
Since I will be making great use of cookies in the next chapter and later, I will not explain this method now. Basically it boils down to keeping an ID as a pointer to a record in a database, a file on disk and so on. Normally you shouldn't use cookies to maintain large amounts of information for two reasons: first of all they are limited in size and second of all they are not very *secure* as we could say. Anyone can examine the contents of a cookie. Keeping information like passwords, etc in there isn't wise. Instead you could keep an integer value for example that points to a record where the user's personal information is stored. You could also opt for encoding the information before sending it to the cookie and then decoding when retrieving, but really I don't see much point into going to all the trouble.
Having said that, let's examine the other two methods for passing information from one state to another.
URL's Response.SendRedirect('http://localhost/scripts/example.dll/redirect?params='+Request.ContentFields.Values['THE_FIELD']).
In this line, we are calling our dll again. However we are also passing information that we retrieved in this action from the content fields of the form (in particular THE_FIELD field).
Notice, that in the new call (redirect), you would only have access to the information via the QueryFields.
HIDDEN FIELDS Let's say you have an HTML form that calls an action in your DLL. Add to this form a hidden field and set the value to be equal to an html transparent tag, as in:
In your call to the DLL, put a PageProducer and replace the value of the tag with the information you need to pass to the next request.
if TagString = 'STATE_FIELD1' then ReplaceText := 'State_information';
Also make sure of course that the result is contained in a form so you could then have access to this field with the ContentFields property. In you next action, all you need to do to read this information is:
Request.ContentFields.Values['STATE_FIELD1'].
This method implies a bit more work on your part the using URL's or cookies to pass information. Also all the pages have to be processed with a PageProducer.
Next page > Database enabled applications > Page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
|
|||||||||||||||
All graphics (if any) in this feature created by Zarko Gajic.
| More Delphi |
|
· Learn another routine every day - RTL Quick Reference. · Download free source code applications and components. · Talk about Delphi Programming, real time. · Link to the Delphi Programming site from your Web pages. · Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC. |
|
· NEXT ARTICLE:
ADO Cursors - DB/10. Chapter ten of the free Delphi Database Course for beginners. How ADO uses cursors as a storage and access mechanism, and what you should do to choose the best cursor for your Delphi ADO application. |
| Stay informed with all new and interesting things about Delphi (for free). |
|
|
| Got some code to share? Got a question? Need some help? |

