Advertisement
Guest User

Untitled

a guest
Jan 13th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. <form action="loginprocess.jsp">
  2. Email:<input type="text" name="email"/><br/><br/>
  3. Password:<input type="password" name="pass"/><br/><br/>
  4. <input type="submit" value="login"/>
  5. </form>
  6.  
  7. <%@page import="bean.LoginDao"%>
  8. <jsp:useBean id="obj" class="bean.LoginBean"/>
  9.  
  10. <jsp:setProperty property="*" name="obj"/>
  11.  
  12. <%
  13. boolean status=LoginDao.validate(obj);
  14. if(status){
  15. out.println("You r successfully logged in");
  16. session.setAttribute("session","TRUE");
  17. }
  18. else
  19. {
  20. out.print("Sorry, email or password error");
  21. %>
  22. <jsp:include page="index.jsp"></jsp:include>
  23. <%
  24. }
  25. %>
  26.  
  27. import java.sql.Connection;
  28. import java.sql.DriverManager;
  29. import java.sql.ResultSet;
  30. import java.sql.Statement;
  31. public class LoginDao {
  32. //public static void main(String args[]){
  33. public static boolean validate( LoginBean bean ){
  34. Connection c = null;
  35. Statement stmt = null;
  36. boolean status=false;
  37. try{
  38.  
  39. Class.forName("org.postgresql.Driver");
  40. c = DriverManager.getConnection("jdbc:postgresql://localhost:5432/test","postgres", "pgadmin");
  41. // c.setAutoCommit(false);
  42. //PreparedStatement ps=c.prepareStatement("select * from user432 where email=? and pass=?;");
  43. //ps.setString(1,bean.getEmail());
  44. //ps.setString(2, bean.getPass());
  45. stmt = c.createStatement();
  46. ResultSet rs = stmt.executeQuery( "SELECT * FROM public."USER432" where email= 'a' and pass='a' ;" );
  47. //ResultSet rs = stmt.executeQuery( "SELECT * FROM public.company;" );
  48. status=rs.next();
  49. rs.close();
  50. stmt.close();
  51. c.close();
  52. }catch(Exception e){}
  53. //System.out.println(status);
  54. return true;
  55.  
  56.  
  57.  
  58. }
  59. }
  60.  
  61. package bean;
  62.  
  63. public class LoginBean {
  64. private String email,pass;
  65.  
  66. public String getEmail() {
  67. return email;
  68. }
  69.  
  70. public void setEmail(String email) {
  71. this.email = email;
  72. }
  73.  
  74. public String getPass() {
  75. return pass;
  76. }
  77.  
  78. public void setPass(String pass) {
  79. this.pass = pass;
  80. }
  81.  
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement