2

I'm working on a project on Online Examination. In this when the question paper is shown then the user can go back to the previous page. How can i prevent the user to access the previous page.

Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117

2 Answers2

3

You can't prevent a user from clicking the Back button of the browser.

What you can do, though, is maintaining a state in the session.

Example:

When the user accesses a question page, the number of the requested question is compared to the number kept in the session. If it is greater or equal, the number in the session is updated and the access is granted. If it is less, the access is denied and the response is a page that explains why.

Laurent Pireyn
  • 6,735
  • 1
  • 29
  • 39
  • will you please elaborate this. how to use it in practical(code) – Mohammad Faisal Apr 28 '11 at 00:33
  • @Mohammad Faisal: I can't elaborate further since I have no idea about the context of your web application. You should be able to implement my suggestion quite easily; many tutorials exist for Servlets and JSP. – Laurent Pireyn Apr 29 '11 at 21:01
  • We can prevent a user to use the back button of the browser. There must be any script to stop the use of back button. – Mohammad Faisal Jul 04 '11 at 16:38
  • @Mohammad Faisal: There is no way to enforce the order of the URLs requested by the clients: HTTP is a stateless, not connected protocol, and the clients ultimately decides which URL they request. Some JavaScript tricks exist to control the Back button to some extent, but they are annoying and very easy to circumvent. – Laurent Pireyn Jul 04 '11 at 21:08
1

if you handle session manually in your application than you remove all session variable from your application and put the following java script in your page on onload function where u redirect after logout

<html>

<head>
  <script type="text/javascript">
    window.history.forward();

    function noBack() {
      window.history.forward();
    }
  </script>
</head>

<body onload="noBack();" onpageshow="if (event.persisted) noBack();">
  <!-- your html/jsp code -->
</body>

</html>
Mohammad Faisal
  • 5,783
  • 15
  • 70
  • 117
Piyush Chaudhari
  • 962
  • 3
  • 19
  • 41