Re: Session Variables posted by: venugopal reply Thursday, Nov 9, 12:43 AM iam giving a login code and after login seesion validation please compare and see it may work for you -------> //import packages import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; import java.sql.*; public class Memberlogin extends HttpServlet { private BENConnectionPool pool; public void init(ServletConfig config) throws ServletException { super.init(config); try { System.out.println("before connection opened"); pool=new BENConnectionPool("jdbc:odbc:banner","banner","banner","sun.jdbc.odbc.JdbcOdbcDriver",1,1); System.out.println("after connection opened"); } catch(Exception e) { System.out.println(e); } } public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException { res.setContentType("text/html"); PrintWriter out=res.getWriter(); Connection con=null; PreparedStatement pst=null; Statement st=null; ResultSet rs=null; boolean CorrectUser=false; boolean Received=false; String m_strMemberid =req.getParameter("Username"); System.out.println("Name:"+m_strMemberid); String m_strPassword =req.getParameter("Password"); System.out.println("Pass:"+m_strPassword); System.out.println("This iis for data base checking"); try { con=pool.getConnection(); String checkingUserid="select memberid,password from bendetails where memberid=? and password=?"; pst=con.prepareCall(checkingUserid); pst.setString(1,m_strMemberid); pst.setString(2,m_strPassword); rs=pst.executeQuery(); System.out.println("After RS"); if(rs.next()) { out.println ("User id &password are correect go ahead"); HttpSession session=req.getSession(true); session.putValue("username",m_strMemberid); session.putValue("password",m_strPassword); CorrectUser=true; //res.sendRedirect("http://client0187:8080/URLList.html"); } else { out.println ("User id &password are incorrect "); res.sendRedirect("http://client0187:8080/Invalidlogin.html"); } String ReceivedAnyCredits="select idreceived,transfer_result_flag from bentransferdetails where idreceived='"+m_strMemberid+"' and transfer_result_flag='F'"; if(CorrectUser) { System.out.println("valid user"); st=con.createStatement(); rs=st.executeQuery(ReceivedAnyCredits); while(rs.next()) { Received=true; System.out.println("he received"); } res.sendRedirect("http://client0187:8080/URLList.html"); } } catch(Exception e) { System.out.println(e); } finally { try { if(rs!=null) { rs.close(); } if(pst!=null) { pst.close(); } } catch(Exception e) { System.out.println(e); } if(con!=null) { pool.returnConnection(con); } } } } ================ after login please see this /*click banner*/ import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; public class ClickBanner extends HttpServlet { private BENConnectionPool pool; public void init(ServletConfig sc)throws ServletException { super.init(sc); try { pool=new BENConnectionPool("jdbc:odbc:banner","banner","banner","sun.jdbc.odbc.JdbcOdbcDriver",1,1); } catch(Exception e) { System.out.println(e); } } public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException { res.setContentType("image/gif"); res.setHeader("Pragma","no-cache"); ServletOutputStream out = res.getOutputStream(); Connection con=null; ResultSet rs=null; Statement st=null; boolean flag=false; String urlstring=""; try { int r_urlid=Integer.parseInt(req.getParameter("banner")); con=pool.getConnection(); st=con.createStatement(); HttpSession bannersession=req.getSession(false); Integer s_urlid=(Integer)bannersession.getValue("DisplayBannerURLID"); int clickbannerurlid= s_urlid.intValue(); bannersession.invalidate(); System.out.println("End of the click Banner 1 "); String query1="select url from bensitedetails where urlid="+clickbannerurlid; rs=st.executeQuery(query1); System.out.println("End of the click Banner 2 "); // HttpSession downlinesession = req.getSession(true); // downlinesession.putValue("DownlineURLID",new Integer(r_urlid)); while(rs.next()) { urlstring=rs.getString(1); flag=true; } if(flag) { res.sendRedirect(urlstring); String query6= " update benstatistics set clickthrusjoin=clickthrusjoin+1,clickthrusreset=clickthrusreset+1 where urlid="+clickbannerurlid; st.executeUpdate(query6); con.commit(); } System.out.println("End of the click Banner class"); } catch(Exception e) { System.out.println(e); } } }