I've dived with hundreds of sharks and how to react depends on the species, but in general, most of the advice above is sound - sharks rarely attack divers, and if they do it is because you have either really annoyed them (even if you didn't know that) - reasons might include territorial defense, perception of competition for a food source - or it's a case of mistaken identity in poor viz. It can happen though, and other users of this forum have had the experience.
Most sharks (I've dived with plenty) are skittish and wary of humans - after all you are 2 metres long and made of metal and bubbles, but some are very curious and will make close approaches (The oceanic white tip is renowned for this)
If you are lucky enough to see one - take lots of pictures! They are the most beautiful creatures. The classic "killers" - Great Whites, Tigers, Oceanic White Tips, Bulls, do not wholly deserve their reputation, but they are apex predators with several million years of evolution behind them and of course should be treated with extreme caution - and should they display aggressive behaviour, keep your eyes on the animal, don't make sudden movements, back to the reef or sink to the bottom where you are less of a target, bring the dive group together and calmly exit the water.
As a last resort, charging the shark is an option - Walter has a wonderful story about this - but it's not something I would like to attempt!
Don't try to pet the animals! Even a filter-feeding whale shark has the potential to be harmful if it decides to slap you with 6 metres of extremely powerful tail muscle!
In general, it is not something you should be worried about - and I'd rather come face to face with a Tiger shark (and have done so) than a wild bear.
I have been attacked by two species of fish underwater (unprovoked) - the Titan Triggerfish during mating season, and the clownfish (nemo). These for sure have got bigger cojones than your average shark...
And finally the old joke:
Diver 1: What do we do if we see a Great White?
Diver 2: Swim away as fast as possible!
Diver 1: Don't be ridiculous, you'll never out-swim a great white!
Diver 2: No, but I can swim faster than you!
Enjoy them while we still have them,
C.