As others have said, the best thing you can do is make a 'U-shaped' formation of your infantry at your end of the bridge. I reccomend having any axe-men on the flanks of the formation, spearmen on the curves, and any swordsmen in the middle of it. Any Archers and non-skirmisher units should be positioned level with the bridge on the flanks, so that they can fire on the enemy as they come in. Ballistae and catapults can annhilate an enemy like this, but remember that trebuchets will not work very well against a bridge.

If you are attacking a bridge, I think the best way is to use the same formation, only use a skirmisher unit or cavalry as bait. Bring a skirmisher unit up to the enemy, pepper them a bit, then retreat when they give chase. They'll go right int your little trap, and Ballistae firing forward onto a bridge covered with enemies? slaughter.