The true answer is there is no real way to stay alive. You will always be encountering different situations where some strategies that may work in other situations do not apply. There are many different ways to play each class, and everyone is different, so you will never really know what to expect or how different people will react. One thing I try to do when I am a soldier is to always try and keep in the air. By rocket jumping into the air, you are not only accelerating and moving in all sorts of different directions, but you are becoming a smaller target. Every shot needs to count because 2 or 3 rocket jumps and your just about out of health. I really like to use this strategy with demo, and sticky jump into the air over a bunch of people on the Payload cart, unload stickies on them as fast as I can and just detonate them. It works exceptionally well because most often they do not know you are right above their head, and if you get a crit they are toast. Just make sure to stand behind the bushes when your launching yourself.

As for pyro, I am rather unexperienced with that class. One thing I think is a great tool to use that you should learn to use is the reflector. It has saved me dozens of times. The pyro, being a low health class, is extremely vulnerable with head-on or even flanking tactics. It operates best soley on suprise and ambush. Maps such as Gold Rush and Badwater have a few, confined spaces that you should seek out, hide in and wait for the moment. The backburner is more appropriate for this situation. I find that the reflector is more inspiring of my head-on style of playing, and that is why I most often use it. Beware though, as it will not reflect bullets, so unless your attacking a soldier or demo, it is usually best to get out of there. I hoped this helps. I play a lot more heavy, than pyro or soldier, but that is a completely different animal and is best left for another day.