Long or short sightedness is usually caused by a part of your eye not being quite the right shape – like the lens or the eyeball. This means that the images you see are not quite in focus at the back of your eye on the retina. Glasses or lenses correct this so that the image is in focus on the retina. Have a look at this picture – it illustrates it quite well (the top picture shows shortsightedness (myopia) and the bottom correction of it with glasses): http://en.wikipedia.org/wiki/File:Myopia.svg.
For nearsightedness, glasses correct the problem of the eyeball being too long to focus upon a far away image projected onto the retina. The glasses offer a concave lens that bends light rays outward, which normalizes the eyeball. In farsightedness, the eyeball is too short to focus upon objects that are near. Glasses use a convex lens that bends the light inward before it reaches the eye’s lens, thereby correcting vision.