File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes JSP Logout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP Logout" Watch "JSP Logout" New topic
Author

JSP Logout

Ashok Haluvarthi
Greenhorn

Joined: Jul 04, 2002
Posts: 13
Hello every one,
i have one index.html in which username and password will be send to login page like this....
my prob is when i press logout button the session has to invalidate but when i press back button from IE Browser it will again enter in to the data page what may be the prob....
Code...
index.html
<html>
<form name="form1" method="post" action="login.jsp">
<input type="text" name="username">

<input type="password" name="password">
<input type="submit" name="Submit" value="Login" >
</font></p>
</form>
</html>
login.jsp
<html>
<body background="back_right.gif">
<head>
<%
response.setHeader("cache-control","no-cache");
response.setHeader("pragma","no-cache");
response.setDateHeader("Expries",0);

%>
</head>
<%
String u_name=request.getParameter("username");
String p_name=request.getParameter("password");
String pass="";

%>
<input type="hidden" name="username" value="<%= u_name %>">
<jsp:usebean id="dbbean" scope="page" class="com.redfern.DBQuery" />
<%
pass=dbbean.getPassword(u_name);
if(p_name.equals(pass))
{
session.setAttribute("user",u_name);
%>
<jsp:include page="data.jsp" />

<% }
%>

</body>
</html>
BEAN DBQuery.java file
package com.redfern;
import java.util.*;
import java.sql.*;

public class DBQuery
{
String password="";

public String getPassword(String u_name)
{
String url="jdbc dbc:lesolei";
String user="scott";
String pass="tiger";

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url,user,pass);
Statement stm= con.createStatement();
ResultSet rs= stm.executeQuery("select password from ashok where username='"+u_name+"' ");
while(rs.next())
{
String return1=rs.getString(1);
password=return1;
}
rs.close();
if(password=="")
{
password="No Password Found for"+password;
}
}//try
catch(Exception e){password="There was an Error"+e;
}//end catch
return password;
}
}
and data.jsp
<html>
<head>
<title>Termination Report</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
<%
if(session.getAttribute("user")== null){ %>
<jsp:forward page="index2.htm" />
<% } %>
<%
response.setHeader("cache-control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader("Expires",0);
%>
</head>
<body>
<%= "Hello" %>
<%
out.println(session.getAttribute("user"));
%>
<form action=logout.jsp>
<input type=submit name=send value=logout>
</form>
</body>
</html>
logout.jsp

<%
session.setAttribute("user",null);
session.invalidate();
response.sendRedirect("index.html");
%>
Pls help me out it is very urgent
 
Consider Paul's rocket mass heater.
 
subject: JSP Logout
 
Similar Threads
Setting session to true and then invalidating
Logout The Session
passing multiple values from one page to another
session handling problem
disable the back button in webapplication