To defend against cavalry:
I use boxes to defend cav charges. When you defend, don't target the cav or your troops will follow and get disorganized. Instead move your troops on routes that intercept the cav. You can figure out where the attack will come based on the holes in your own defense.
If the cav run straight through a unit they don't deal all that much damage. If they charge through a couple spears or glaves they take more damage. Keep your units close and the opponent will just shred their own cav and do little damage. Try not to bunch though or the enemy can take advantage of that with ranged units.
Practice cav charges yourself and you will find ways to counter it.