user8611954 wrote:
we want to fire a javascript, that will alert user showing popup with warning (You would loose data if you go Back ! ) and then Ok button and Cancel button on it.

Really? In this day and age where everyone installs popup blockers (or browsers just come with them built in) you still want to commit the cardinal sin of web app design (other than showing blinking text)?

If user click Ok then he would go to previous page ( page1.jsp). If user clicks Cancel button then ofcourse user will stay on same page (page2.jsp).
Can anyone share implenmented such script that works on all browsers ?

Javascript provides an event for it.

http://stackoverflow.com/questions/1704533/intercept-page-exit-event

Twas an easy Google, took me about 20 seconds. Also note that Javascript is in no way related to Java; off-topic questions are usually locked.