I know that the Confederate States of America needed an important victory,but what else built up leading to the battle of Gettysburg? Oh and why Gettysburg?
Lee was coming off an absolutely devastating victory over the Union army under Hooker at the Battle of Chancellorsville. His decision to invade the north was based on a few things:
Lee didn't know exactly where the Union army was because his cavalry had gone off raiding. Lee had no particular desire to fight at Gettysburg. His subordinate, division commander Harry Heth, claimed in his memoirs that he sent troops into the town because he had heard there was a shoe factory there, and many of his troops badly needed shoes, but some historians dispute this. But whatever the reason, the troops headed toward the town. Before they quite got there, they bumped into some Union cavalry and got tangled up fighting them. From that point, both sides (with poor coordination and without really understanding what was going on) started feeding more and more troops into the battle. Gradually, more and more senior commanders arrived at the battle and more and more troops got involved, until the thing kind of took on a life of its own. All through the battle, Lee and various other Confederate commanders considered breaking it off at various points and continuing their strategic maneuvering elsewhere. In the end, Lee decided to fight it out, and the rest you know.
Sources: On Lee's thinking:
Coddington, Edwin B. The Gettysburg Campaign; a study in command. New York: Scribner's, 1968. ISBN 0-684-84569-5.
See James M. McPherson, "To Conquer a Peace? Lee's Goals in the Gettysburg Campaign." Civil War Times (2007) 46(2): 26-33.
For the controversy surrounding Heth and the Shoes, see:
Eicher, David J. The Longest Night: A Military History of the Civil War. New York: Simon & Schuster, 2001. ISBN 0-684-84944-5