A variational approach to a class of singular semilinear elliptic equations