Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Connection Bean

 
vinu pillai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
How to make a bean for connecting to Database through JSP..???
I have no idea what bean are....i hard code the jdbc syntaxes in the scriptlet tag itself...but some say that making a connection bean is proper way to show the database results...
i don't know how to create bean ...can help me out to find the best tutorial links to JavaBeans..

Thanks..
VINU
 
Toyin Sogeke
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sir,
Create javabean as follows:
// Assign page name, very important
package example.test;
public class LoginCheck {
private String userName = "";
private String passWord = "";
// Default constructor is required.
public LoginCheck() { }
// JavaBean needs setter and getter methods
public void setUserName(String user) {
this.userName = user;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
// You can define a method here with
// your database connection details.
public boolean authenticate(String user) {
return (this.username.equalsIgnoreCase(this.userName));
}
}
You can use a JavaBean as follows in a JSP:
<jsp:useBean id="loginBean"<br /> scope="page"<br /> class="example.test.LoginCheck">
<jsp:setProperty name="loginBean" property="*"/>
</jsp:useBean>
<%<br /> // You can call and use a JavaBean as follows:<br /> boolean isLoggedIn = loginBean.authenticate("RanchHand");<br /> %>
Hope this helps.
Cheers
Originally posted by vinu pillai:
hi all,
How to make a bean for connecting to Database through JSP..???
I have no idea what bean are....i hard code the jdbc syntaxes in the scriptlet tag itself...but some say that making a connection bean is proper way to show the database results...
i don't know how to create bean ...can help me out to find the best tutorial links to JavaBeans..

Thanks..
VINU

 
vinu pillai
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks buddy,
I will deploy it soon...
bye...
Thanks again
Originally posted by Toyin Sogeke:
Hello Sir,
Create javabean as follows:
// Assign page name, very important
package example.test;
public class LoginCheck {
private String userName = "";
private String passWord = "";
// Default constructor is required.
public LoginCheck() { }
// JavaBean needs setter and getter methods
public void setUserName(String user) {
this.userName = user;
}
public void setPassWord(String passWord) {
this.passWord = passWord;
}
// You can define a method here with
// your database connection details.
public boolean authenticate(String user) {
return (this.username.equalsIgnoreCase(this.userName));
}
}
You can use a JavaBean as follows in a JSP:
<jsp:useBean id="loginBean"<br /> scope="page"<br /> class="example.test.LoginCheck">
<jsp:setProperty name="loginBean" property="*"/>
</jsp:useBean>
<%<br /> // You can call and use a JavaBean as follows:<br /> boolean isLoggedIn = loginBean.authenticate("RanchHand");<br /> %>
Hope this helps.
Cheers

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic