dcsimg
how can i access a module defined in a java bean from a jsp page
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sheela_oba
Posted On:   Wednesday, October 31, 2007 12:16 PM

Below is my java bean class in which i defined a module called verifyregis(),where i established a JDBC connection to verify whether given username and password already exists in the database, if they already exists the boolean value for registered variable is true else it is false i just called this module in a jsp page and checked whether if registered value is true i just want to go to one page and if false i want to go to another page...i just could not get the code correct in the jsp page, i could not access the module in java bean class in jsp page... package myproject; import java.sql.*; public class myprojbean { private String id;    More>>

Below is my java bean class in which i defined a module called verifyregis(),where i established a JDBC connection to verify whether given username and password already exists in the database, if they already exists the boolean value for registered variable is true else it is false



i just called this module in a jsp page and checked whether if registered value is true i just want to go to one page and if false i want to go to another page...i just could not get the code correct in the jsp page, i could not access the module in java bean class in jsp page...





  1. package myproject;
  2. import java.sql.*;
  3. public class myprojbean
  4. {
  5. private String id;
  6. private String passwd;
  7. private String retypepwd;
  8. private String fname;
  9. private String lname;
  10. private String gender;
  11. private boolean registered;

  12. public myprojbean()
  13. {}

  14. public void setid(String id)
  15. {
  16. this.id=id;
  17. }
  18. public String getid()
  19. {
  20. return id;
  21. }
  22. public void setpasswd(String passwd)
  23. {
  24. this.passwd=passwd;
  25. }
  26. public String getpasswd()
  27. {
  28. return passwd;
  29. }
  30. public void setretypepwd(String retypepwd)
  31. {
  32. this.retypepwd=retypepwd;
  33. }
  34. public String getretypepwd()
  35. {
  36. return retypepwd;
  37. }
  38. public void setfname(String fname)
  39. {
  40. this.fname=fname;
  41. }
  42. public String getfname()
  43. {
  44. return fname;
  45. }
  46. public void setlname(String lname)
  47. {
  48. this.lname=lname;
  49. }
  50. public String getlname()
  51. {
  52. return lname;
  53. }
  54. public void setgender(String gender)
  55. {
  56. this.gender=gender;
  57. }
  58. public String getgender()
  59. {
  60. return gender;
  61. }
  62. public void verifyregis()throws
  63. SQLException,ClassNotFoundException
  64. {
  65. Connection con=null;
  66. PreparedStatement pstmt;
  67. ResultSet rs;
  68. try
  69. {
  70. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  71. con=DriverManager.getConnection("jdbc:odbc:oradsn","scott","tiger");
  72. pstmt=con.prepareStatement("select id,passwd from login_info where id='"+id+"' and passwd='"+passwd+"'");
  73. rs=pstmt.executeQuery();
  74. while(rs.next())
  75. {
  76. if(id.equalsIgnoreCase(rs.getString(1))&&passwd.equalsIgnoreCase(rs.getString(2)))
  77. registered=true;
  78. }
  79. else
  80. {
  81. registered=false;
  82. }
  83. rs.close();
  84. }
  85. finally
  86. {
  87. con.close();
  88. }
  89. }
  90. public void insertdata()throws SQLException,ClassNotFoundException
  91. {
  92. Connection con=null;
  93. PreparedStatement pstmt=null;
  94. ResultSet rs;
  95. String str="insert into login_info values(?,?,?,?,?,?)";
  96. try
  97. {
  98. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  99. con=DriverManager.getConnection("jdbc:odbc:oradsn","scott","tiger");
  100. pstmt=con.prepareStatement(str);
    pstmt.setString(1,id);
  101. pstmt.setString(2,passwd);
  102. pstmt.setString(3,retypepwd);
  103. pstmt.setString(4,fname);
  104. pstmt.setString(5,lname);
  105. pstmt.setString(6,gender);
  106. pstmt.executeUpdate();
  107. }
  108. finally
  109. {
  110. con.close();
    }
    }
    }




jsp page:



  1. <%@ page errorPage="/error.jsp"%>
  2. class="myproject.myprojbean"/>

  3. <% boolean b=myprojbean.verifyregis();%>
  4. <% if(b==true)
  5. {%>

  6. <%}else{%>

  7. <%}%>

   <<Less
About | Sitemap | Contact