Login With Java Session /How Use session object in java ???
public class CheckLogin {
public void checkValid(UserDetail bean){
String sql="SELECT * FROM tablename WHERE user=?";
Connection con=DBcon.getConnection(); //singleton database object
try {
PreparedStatement pstm=con.prepareStatement(sql);
pstm.setInt(1,"jnext");//username
ResultSet rs=pstm.executeQuery(); //execute query
if(rs.next()){
System.out.println("WEL-COME jnext Development : ");
HttpSession session=req.getSession(true); // session start for new user
session.setAttribute("ky", "jnext"); // set user name on session scope
RequestDispatcher rd;
rd=req.getRequestDispatcher("abc.jsp"); // redirect after login page
rd.forward(req, resp);
}
} catch (SQLException e) {
System.out.println("sql exception please check sql query");
e.printStackTrace(); //print exception
}
}
}
}
public class CheckLogin {
public void checkValid(UserDetail bean){
String sql="SELECT * FROM tablename WHERE user=?";
Connection con=DBcon.getConnection(); //singleton database object
try {
PreparedStatement pstm=con.prepareStatement(sql);
pstm.setInt(1,"jnext");//username
ResultSet rs=pstm.executeQuery(); //execute query
if(rs.next()){
System.out.println("WEL-COME jnext Development : ");
HttpSession session=req.getSession(true); // session start for new user
session.setAttribute("ky", "jnext"); // set user name on session scope
RequestDispatcher rd;
rd=req.getRequestDispatcher("abc.jsp"); // redirect after login page
rd.forward(req, resp);
}
} catch (SQLException e) {
System.out.println("sql exception please check sql query");
e.printStackTrace(); //print exception
}
}
}
}
contace me :ghorivipul97@gmail.com
No comments:
Post a Comment