Variational construction of connecting orbits