• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JSP Logout

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
It sure was nice of your sister to lend us her car. Let's show our appreciation by sharing this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic