If the attack continues for more than several minutes, consider fighting back. First - try to escape, preferably to a building, car or up a tree. If you can't escape, or if the bear follows, use bear spray, or shout and try to intimidate the bear with a branch or rock. Do whatever it takes to let the bear know you are not easy prey. This kind of attack is very rare but can be very serious because it often means the bear is looking for food and preying on you.
Recent research indicates that bear spray can be effective against some bears when used properly.
If you plan to carry it, be aware that wind, spray distance, rain and product shelf life can all influence how well it works. Carefully read directions on the can prior to your trip. The best way to live safely with bears is to avoid contact with them.