Results 1 to 6 of 6
Thread: logout by disabling back button
- 02-04-2010, 05:16 AM #1
Member
- Join Date
- Feb 2010
- Posts
- 3
- Rep Power
- 0
logout by disabling back button
hello friends...
i am a new user...
i am creating a web appliction in which i want
if the user is been logout once then he should not be able to access the home page by simply pressing the back button...
i tried different things but it didn't work...
pls help...
login.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>LOGIN PAGE</title>
</head>
<body>
<form action="Loginpage">
<input type="text" name=username value="username"><br/>
<input type="password" name=password value="pass"><br/>
<input type="submit" name= hitme value="hit me"><br/>
</form>
</body>
</html>
servlet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out=response.getWriter();
HttpSession session =request.getSession();
String name = request.getParameter("username");
request.setAttribute("uname",name);
out.print("<html>");
out.print("<head>");
out.print( "<style type='text/css'>");
out.print("h3 {color:sienna;}");
out.print("h3 {margin-left:20px;}");
out.print("</style>");
out.print("</head>");
out.print("<h1>hi </h1>");
out.print("<h2> welcome </h2>");
out.print("<h3>");
out.print(name);
out.print("</h3>");
out.print("</html>");
RequestDispatcher rd= request.getRequestDispatcher("/home1.jsp");
rd.forward(request, response);
}
}
home page
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1> 1st page</h1>
<%
request.getSession(true);
String val = (String)request.getAttribute("uname"); %>
<h2><%= val%></h2>
<a href="/LoginForm/logout.jsp" > logout</a>
</body>
</html>
logout.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
request.getSession(true);
System.out.println("1");
session.invalidate();
System.out.println("2");
response.sendRedirect("logout2.jsp");
%>
</body>
</html>
logout2.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%request.getSession(true); %>
<h1> Successful log out</h1>
</body>
</html>
so pls help me friends...
- 02-04-2010, 08:57 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
First off, separate code from diaplay. You have html in your servlets, and Java in your JSPs. This is not good practice.
You'll want a login servlet that handles the login, and forwards to the home page. It doesn't write to the out stream!
You'll want a logout servlet that logs you out and then forwards to a jsp page that says you've logged out. You don't put the log out code in the JSP.
- 02-04-2010, 09:44 AM #3
Member
- Join Date
- Feb 2010
- Posts
- 3
- Rep Power
- 0
logout by restricting the user to use back button..
ok i have removed all the html code from the servlets and tried to minimise the java code in jsp pages..
thanks for the advise ...
but my real question of how to restrict the user to goto the home page by pressing the back buttom is still there..
can any one give me code how to
invalidate the user in tho logout page and again if he tries to press the back button, the code should direct it to the login page...
pls pls pls help me guys...
- 02-04-2010, 09:53 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Check if the user is logged in?
That's what you usually do.
If the user isn't logged in then redirect.
- 02-04-2010, 10:53 AM #5
Member
- Join Date
- Feb 2010
- Posts
- 3
- Rep Power
- 0
give me some code..
pls give some code brother...
i am completely messed up..wid my code...
- 02-04-2010, 11:04 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
how to make graphic 'painted' on a button visible after disabling??
By nit_go in forum AWT / SwingReplies: 2Last Post: 01-30-2010, 05:14 AM -
problem with back button of the browser.
By shivakumari in forum Java ServletReplies: 2Last Post: 03-25-2009, 07:41 AM -
Disabling a button at EOF
By dbashby in forum New To JavaReplies: 1Last Post: 03-10-2009, 02:37 PM -
Back button
By Tokajac in forum Web FrameworksReplies: 1Last Post: 11-27-2008, 05:27 AM -
[SOLVED] Disabling a button not working
By Leprechaun in forum New To JavaReplies: 2Last Post: 04-24-2008, 04:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks