Mitt Romney was in Virginia on Thursday to do what he has been trying to do a lot lately: reach voters in places where he had hoped to be faring better by now. On this day, his targets were military veterans and active-duty service members, a once-reliably Republican group that recent polls show to be closely split between the two candidates.

That near-parity may explain something else that happened Thursday: President Obama did almost exactly what Romney did. He visited Virginia, and he talked about veterans and the military.

It was not quite a choreographed dance, but with just 39 days until the election, the two are spending much of their time in the roughly half a dozen states expected to decide the race.

With fresh polls giving Obama an edge in most of these places, the sequence goes something like this: Romney hits the ground trying to build momentum, then Obama does the same, counter-messaging and counter-punching to block any Romney gains.

On Thursday, Romney addressed a few hundred veterans at an American Legion hall in Springfield. The Republican seized on the automatic cuts to the defense budget scheduled to take effect next year, as well as unrest in the Middle East and around the world, to paint the president as a weak commander in chief and poor guardian of U.S. military strength.

“It is still a troubled and dangerous world, and the idea of cutting our military commitment by a trillion dollars over this decade is unthinkable and devastating,” Romney said. “And when I become president of the United States, we will stop it. I will not cut our commitment to our military.”

Obama, meanwhile, queued up Sen. James Webb (D-Va.), a former Navy secretary and decorated Vietnam veteran, to introduce him to a crowd of 7,000 in Virginia Beach. Webb criticized Romney for not paying tribute to veterans and service members in his speech at the Republican National Convention in August — and for saying that nearly half of Americans who don’t pay taxes consider themselves “victims” who are entitled to federal benefits. That group includes veterans, Webb said, and he criticized Romney as a member of the Vietnam-era generation who chose not to serve.

“Those among us who stepped forward to face the harsh unknowns and the lifelong changes that can come from combat did so with the belief that their service would be honored,” Webb said.

Advisers to Obama and Romney declined to comment on Webb’s references to Romney’s lack of military service, although a Romney spokesman said on the condition of anonymity that Romney entered the draft after his deferment ended and that his number was never called.

Obama also did not serve in the military, but took credit in his speech to the veterans for making good on his promises to wind down the wars in Iraq and Afghanistan, for diminishing al-Qaeda and for ordering the mission that killed Osama bin Laden.

“As long as I’m commander in chief, Virginia, we will sustain the strongest military the world has ever known,” the president said under the roof of an open-air amphitheater, three enormous U.S. flags billowing opposite the stage. “And as Jim Webb so eloquently stated, when our troops take off their uniforms, we will serve them as well as they’ve served us, because nobody who fights for this country should have to fight for a job or a roof over their heads when they come home.”

Thursday was the second straight day Obama and Romney stumped in the same state. The two appeared in Ohio on Wednesday, and both will be in Colorado next week after their first debate. Advisers to both said they are not intentionally following each other, but with the election likely to be decided by a handful of states, it is inevitable that the two will be close to each other some days.

Romney’s standing among veterans speaks to the larger reality that he is underperforming among several groups considered essential to a Republican victory.

A Washington Post poll in Virginia this month found Romney and Obama running close among likely voters who are veterans or active-duty military — 51 percent for Romney, and 47 percent for Obama.

Romney’s standing appears weaker than past Republican presidential contenders. Results in the Virginia exit poll of 2004 found that George W. Bush won veterans by a margin of 63 percent to 36 percent over Sen. John F. Kerry (D-Mass.). Bush topped Kerry by four points among non-veterans.

Obama lost veterans nationally in 2008. But he won those younger than 60, a better result than Kerry, a decorated Vietnam veteran, achieved four years earlier. Today, Obama is making a significant push in battleground states with large military installations, such as North Carolina and Colorado. Nowhere is the effort more apparent than in Virginia, home to 800,000 military veterans, the highest concentration in the country.

Both candidates tried to link their concern for veterans to the broader economic arguments they regularly make. Obama said the way to prosperity is to preserve and expand government programs — such as job training and college loans. Romney said he would cut government spending to rein in the debt while instituting tax and other policies that he thinks would help small businesses grow.

Scott Clement contributed to this report.