We show how the combination of observations related to strong gravitational lensing and stellar dynamics in ellipticals offers a new way to measure the cosmological matter and dark-energy density parameters. A gravitational lensing estimate of the mass enclosed inside the Einstein circle can be obtained by measuring the Einstein angle, once the critical density of the system is known. A model-dependent dynamical estimate of this mass can also be obtained by measuring the central velocity dispersion of the stellar component. By assuming the well-tested homologous 1/r^{2} profile for the total density distribution in the lens elliptical galaxies, these two mass measurements can be properly compared. Thus, a relation between the Einstein angle and the central stellar velocity dispersion is derived, and the cosmological matter and the dark-energy density parameters can be estimated from this. We determined the accuracy of the cosmological parameter estimates by means of simulations that include realistic measurement uncertainties on the relevant quantities. Interestingly, the expected constraints on the cosmological parameter plane are complementary to those coming from other observational techniques. Then, we applied the method to the data sets of the Sloan Lens ACS and the Lenses Structure and Dynamics Surveys, and showed that the concordance value between 0.7 and 0.8 for the dark-energy density parameter is included in our 99% confidence regions. The small number of lenses available to date prevents us from precisely determining the cosmological parameters, but it still proves the feasibility of the method. When applied to samples made of hundreds of lenses that are expected to become available from forthcoming surveys, this technique will be an important tool for measuring the geometry of the Universe.