Glasss help to focus light onto the back of the eye where it can be detected and sends information off to the brain. If the eye ball is too short or too long, the lense will focus the light into the wrong place. Glasses help to bend the light enough to allow this focussing onto the retina.
Corrective lenses (glasses or contact lenses) are used to treat defects in vision: myopia (shortsightedness — I have this!), hyperopia (longsightedness), astigmatism (irregular curvature of the eye — my brother has this!) and presbyopia (where your eyesight degrades with age).
The different types of lenses help focus light onto the back of the eye (the retina): myopia requires a divergent lens (spreads the light out), whereas hyperopia requires convergent lens (focuses the light).