NAVAL STATION NORFOLK, Va. (WVEC) -- A military judge sentenced Lt. Cmdr. Edward C. Lin to nine years after he shared military secrets and committed other crimes.

Because of his pre-trial agreement, Lin will serve only six years. The judge also ordered that the 40-year-old forfeit all pay and allowances and be dismissed from the Naval service.

Prosecutors had asked LIn be sentenced to 12 years; the defense hoped he would receive no more than 1.5 years. He could have faced up to 36 years in prison.

Prosecutors previously discontinued their efforts to convict Lin of spying for China or Taiwan. In May, they and he entered into a plea agreement. The prosecution said the 40-year-old sold military secrets in order to impress women.

An appeal in the case is automatic.

Lin continues to be held in confinement in the brig at Naval Station Norfolk.