Exact solutions for nondiffracting beams. I. The scalar theory