I believe it's either done using cookies, or by passing (small quantities) of data in the url.
E.g. I use php to pass data on one of my sites: you create an image id number, e.g. 0000001. You link using
www.mysite.com/pic.php?imgid=0000001
The second page then reads the variable imgid as having a value of 0000001. It makes a page in my templated style with 0000001.jpg in the middle, 0000001.txt included below it.
This means my one page produces up to a million image preview pages, all in my template.
If you can't get any help with it let me know and I'll see what I can suggest.