If a black bear charges you, you should prepare to fight it as its intent is very likely to kill you. By and large this is rare, as most black bears are shy of people even bears which are close in proximity to civilization. Many black bear attack survivors got through because they fought the animal, and in most cases a knife would have been involved.
Carrying a gun to protect yourself from a black bear is more hassle than it's worth.
A grizzly is different, as they tend to display more aggressive behaviour to humans and are less shy around people, especially when exposed to them due to proximity. Carrying a high calibre hand gun in grizzly country as a defensive tool for multi day trips is actually not completely unreasonable. I wouldn't do it but I don't really like guns. I also don't live anywhere near grizzly bears. Grizzlies are the ones who are more likely to bat around a human in a fetal position until they get bored, and your chance of living through that is likely better than your odds of winning a fight with a grizzly, unless you can spear or shoot it.
Just coming across an animal in the woods should be no cause for alarm, they are after all, supposed to be there. Eye contact and body language should convey confidence to them that you as well should be there, and that maybe they should give you room.
If they don't go away immediately, (most times they leave before you even know they're there) and assume an aggressive position, do what you do if a human starts to come after you- face the aggressor, move back slowly and see what reaction you get, all the while planning your defense and accessing your weapon.
Having run into many black bears in the woods around here, I have yet to encounter difficulty. If you're really concerned, get a pit bull, that's the best black bear defence I can think of. Bear spray can be effective, but it shouldn't be used until it's the last resort. Don't just spray a bear because you come across one.