Here is my thinking on the matter... depending on whether you think the threat of terrorism was actually as great as it was made out to be, I think the only way you can effectively fight terrorist groups is to take the fight to them. Building up your defenses and attempting to "secure" the nation is nice, but virtually impossible to do. If someone wants to blow up a building or a plane or a train, they will always find a way to do it. Therefor you have to be proactive and try to find them before they find you.
With that said, I felt one reason why we went into Afghanistan and Iraq was because a war in the heart of the Middle East would draw the terrorist groups to our soldiers like a moth to a flame. This would give our military an opportunity to find and either capture or kill Al Qaeda and other groups on their own home turf. While I find it tragic that the people of Iraq and Afghanistan have had to suffer through the last eight plus years of war, I would rather the war be fought there and not here, and though I am deeply saddened by every death of our men and women over there, I would rather it be our trained soldiers in harms way and not the millions of Americans in cities like New York, Los Angeles, etc.