Applying the principle of virtual work, the slice element method, and the variational method proposed in this paper, one can derive the governing equation and transversality conditions for the rupture surface of a sliding mass of retaining wall and shallow foundation under several external conditions. The governing equation, transversality, and boundary conditions can be solved by the finite difference method (FDM) proposed in this paper, so that the rupture surface and its associated earth pressure acting on the retaining wall or the ultimate bearing capacity acting on the foundation can be determined effectively. By comparison of our results with those of some well known earth pressure and bearing capacity estimating methods, it can be concluded that determining the earth pressure on a retaining wall or the ultimate bearing capacity of a shallow foundation by using the variational method and FDM proposed in this paper, a logical and reasonable result can be obtained without the necessity of guessing the rupture surface.