Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

back button

 
Randall Twede
Ranch Hand
Posts: 4385
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
LAXMI VEMARAJU
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4385
3
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what happened randall? Is that script worked?
I am just waiting for the reply.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic