If you mean the "charley horse" kind of cramps you get in the backs of your legs---the kind that wake you up in the middle of the night---I get those too, if I've been on my feet too much.
Make sure you're getting proper nutrition; often, when we're busiest (at work or at school), we forget to eat correctly. Take a multivitamin daily, to ensure you're getting the potassium and magnesium you need (along with other nutrients).
Also, remember to gently stretch your leg muscles, in the same way a runner would stretch before a race. Do this right before bed, to lessen the likelihood of cramps.
When the cramps do hit, all you can do right away is walk them off. If you try to lay/sit still, the muscles will only continue to tighten. After a few minutes of pacing, the cramps usually subside. As for medication, good old aspirin (or other over-the-counter pain relievers) is probably your best best. There are also some OTC medications that contain pain relievers, plus a mild muscle relaxant (they're often marketed for back pain, but muscles are muscles). I think there might even be a couple of products marketed specifically for leg cramps.
Also, try a topical pain-relief "rub" (like Ben-Gay, Aspercreme, etc). These will help the pain---because of the medication in the products, and also because of the "massaging" action when you rub them on. The only drawback with products like these is that you smell like the product afterward (and so does your bed).