Disclaimer: I reserve all the rights of this article.
Part III: Developing session Beans
New EJB module:
Select menu: NEW〉ENTERPRISE〉EJB〉EJB Designer, Pop-up dialog box, select New, select Create Empty EJB Module, click Next, fill in the name trader, all the way OK.
Designing EJBS:
1. New Session Bean: Right-click menu 〉create ejb〉session Bean in the Open EJB Designer window (now JBuilder right window).
2, modify the basic nature of the Bean: name modified to Userinfo,interface for local,session type is stateful, other default.
3, add attributes: Right-click the bean design 〉add〉field, adding username type String,userage type String,logintime type sting.
4, Add methods: Right click on the bean design diagram 〉add〉methed, adding method Showuserinfo, return type is hashmap,interface for local.
5, add Ejbcreate method: Right click on the bean Design 〉add〉ejbcreate, input parameters are: string userName, String userage, string Logintime,home interfaces to Local home.
6. View the bean's code: Right-click the bean design 〉view bean Source to view the code.
The final code is:
-----------------------------------------------
Userinfobean.java Implementation class:
----------------------------------------------
Package trader;
Import Javax.ejb.SessionBean;
Import Javax.ejb.SessionContext;
Import javax.ejb.CreateException;
Import Java.util.HashMap;
Import Org.apache.log4j.Logger;
public class Userinfobean implements Sessionbean {
Private final static Logger _logger = Logger.getlogger (Userinfobean.class);
Public Userinfobean () {
try {
Jbinit ();
catch (Exception ex) {
Ex.printstacktrace ();
}
}
Sessioncontext Sessioncontext;
String UserName;
String Userage;
String Logintime;
public void Ejbcreate (string userName, String userage,
String logintime) throws CreateException {
_logger.debug ("Session Bean is Created.");
This.username = UserName;
This.userage = Userage;
This.logintime = Logintime;
}
public void Ejbcreate () throws CreateException {
}
public void Ejbremove () {
}
public void Ejbactivate () {
}
public void Ejbpassivate () {
}
public void Setsessioncontext (Sessioncontext sessioncontext) {
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.