A combination of molecular dynamics simulations of oscillatory shear flow and continuum mechanics is used to investigate viscoelastic properties of materials confined to molecularly thin films. The atoms of the simple liquid interact via a repulsive Lennard-Jones potential. The chain molecules are modeled as strings of similar spheres connected via finite extensible nonlinear elastic springs. The fluid is confined between two surfaces composed of identical spheres that are moved to simulate oscillatory flow. In order to mimic experiments, the temperature is controlled by coupling the wall atoms to a heat bath, and the viscoelastic properties are obtained via an analysis using continuum mechanics. Both simple and polymeric fluids exhibit linear viscoelastic behavior under typical simulation conditions, although inertial effects play an important role in determining the flow behavior. Simple fluids display a smooth transition from liquidlike to solidlike behavior when confined to molecularly thin films, whereas linear chain polymers and gels display predominantly elastic shear response at all frequencies investigated. These results are in qualitative agreement with the surface forces apparatus experiments on similar systems.