GeeCON Prague 2014*
The moose likes JSP and the fly likes back button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "back button" Watch "back button" New topic
Author

back button

Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

sorry i couldnt think of a good subject name for this thread. the problem is this.
i have a jsp page(it is jsp not html only because it uses the user name from the session) that calls a servlet from a form button. the servlet creates a receipt page and invalidates the session. if the user then clicks the back button he gets a standard error page. i want to replace that with my own page. i have tried several different approaches but keep running into problems. i tried creating an intermediate jsp page that checks if the session is null

<form><input type="button" value="Yes, I'm finished" on_Click="window.location='Watchdog.jsp'"></form>

this doesnt work

<html><head><title>Watchdog</title></head>
<body bgcolor="black">
<% if(request.getSession(false)!=null) {
response.sendRedirect("/examples/servlet/CheckoutServlet");
}
else {
%>
<center><img src="woundeddog.jpg">
<EMBED SRC="dog.au" HIDDEN="TRUE" LOOP="TRUE" AUTOSTART="TRUE">
<% } %>
</body></html>

nor does this

<html><head><title>Watchdog</title></head>
<body bgcolor="black">
<%
import java.io.*;
if(request.getSession(false)!=null) {
PrintWriter out = response.getWriter();
out.println("<script>window.location='/examples/servlet/CheckoutServlet'</script>");
}
else {
%>
<center><img src="woundeddog.jpg">
<EMBED SRC="dog.au" HIDDEN="TRUE" LOOP="TRUE" AUTOSTART="TRUE">
<% } %>
</body></html>

my java skills are very rusty, any help would be appreciated


SCJP
Visit my download page
LAXMI VEMARAJU
Ranch Hand

Joined: Sep 08, 2001
Posts: 38
hi,
I hope this will work.
Give a name to form.
<form name='xxx'>
In the on_click event, call a java script method onBack(), and in java script onBack() place the following code:
document.xxx.action="yourjspfile.jsp";
document.xxx.method="POST";
document.xxx.submit();
"yourjspfile.jsp" is the file, where you want to go when you click the button.
I am sure this will work.
good luck.
laxmi
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

my original post was incorrect. after session is invalidated, if user clicks back he goes back. i want him to see a different page instead. my latest attempt at an intermediate page doesnt redirect

<html><head><title>Watchdog</title></head>
<body bgcolor="black">
<% if(request.getParameter("name")!=null) {
response.sendRedirect("/examples/servlet/CheckoutServlet");
}
%>
<center><img src="woundeddog.jpg">
<EMBED SRC="dog.au" HIDDEN="TRUE" LOOP="TRUE" AUTOSTART="TRUE">
</body></html>

perhaps it just cant be done :roll:
vishal avad
Ranch Hand

Joined: Nov 29, 2001
Posts: 45
hi Randall
If i got your question i would like u to try following solution.
<% if(request.getParameter("name")!=null) { %>
<script language="javascript">
window.location.href="ErrPage.jsp"
</script>
<%
}
%>

OR u can try
<jsp:forward page="ErrPage.jsp" />

instead of javascript. I think after clicking on back button page gets loaded back but from html tag only so try putting the given code inside the body.
HIH
Cheers
vishal
LAXMI VEMARAJU
Ranch Hand

Joined: Sep 08, 2001
Posts: 38
what happened randall? Is that script worked?
I am just waiting for the reply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: back button