Throughout the war, the city was defended by a ring of military forts that mostly deterred the Confederate army from attacking. One notable exception was the Battle of Fort Stevens in July 1864 in which Union soldiers repelled troops under the command of Confederate General Jubal A. Early. This battle was only the second time that a U.S. President came under enemy fire during wartime when Lincoln visited the fort to observe the fighting. (The first had been James Madison during the War of 1812.) Meanwhile, over 20,000 sick and injured Union soldiers were treated in an array of permanent and temporary hospitals in the capital.