People tap on soda cans to avoid a soda explosion from a can that has been shaken up. Tapping may, in fact, decrease the likelihood of such an explosion, but a positive outcome is not guaranteed.
Carbonated beverages contain dissolved carbon-dioxide gas. The way to get gas to dissolve in liquid is to pressurize the mixture, meaning that the pressure inside a soda can is greater than the pressure outside the can. This is why you see little bubbles spray out when you open a soda can -- breaking the seal depressurizes the mixture, causing the gas to come out of solution, starting with the gas closest to the top (that's where the pressure decrease starts). Because gas is lighter than liquid, as soon as it comes out of solution, it rises to escape the can. When it escapes, it carries with it a small amount of liquid from the very top of the can because that liquid is blocking its path.
When you shake a soda can, some of the gas comes out of solution. There are a bunch of carbon dioxide bubbles clinging to the inside of the can, trying to get out. When you open this can and the gas rises to escape, it doesn't only push on the liquid at the very top of the can. Because gas bubbles are stuck to the top, sides and bottom of the can, they force all of the liquid out because all of the liquid is blocking their upward path.
When you tap on the can, you knock bubbles off the bottom and sides of the can, at which point they rise to the top (because gas is lighter than liquid) and there is only a small amount of liquid blocking their escape when you open the can.
Unfortunately, there's no way to tell how many of the bubbles you've displaced in your tapping effort. The wisest course of action is to let the can sit for a while so the gas has time to redissolve. But if you're too thirsty to wait, tapping gently on the can and then slowly popping the top (so the drop in pressure is less sudden) will certainly decrease your chances of getting drenched.
Here are some interesting links: