Welcome to JavaRanch.
A simple way to do this is using a JavaScript timer running on your web page. The exam form should be automatically submitted when the timer expires. From the server-side,
you should record the time that the exam starts, so you can track the mean difference upon the final submission. For no-javascript users, you should have a strategy to decide what to do if the submission was not within the allowed time.