jbuilder2005+jboss-4.0.2rc1+j2sdk1.5+log4j Development Session Bean Ii. (3)

Source: Internet
Author: User
Tags final interface return window jboss log4j
Session
Author: Junsan Jin

Date: 2005-3-30

Version: 1.0

Mailbox: junsan21@126.com; Junnef21@sohu.com

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) {











This.sessioncontext = Sessioncontext;











}



Public HashMap Showuserinfo () {











HashMap userInfo = new HashMap ();











Userinfo.put ("UserName", this.username);











Userinfo.put ("Userage", this.userage);











Userinfo.put ("Logintime", this.logintime);











return userInfo;











}



private void Jbinit () throws Exception {











}











}











----------------------------------------------------











Userinfolocal.java local Remote interface classes:











---------------------------------------------------











Package trader;



Import Javax.ejb.EJBLocalObject;











Import Java.util.HashMap;



Public interface Userinfolocal extends Ejblocalobject {











Public HashMap showuserinfo ();











}











-----------------------------------------------------











Userinfolocalhome.java Local local interface class











-----------------------------------------------------











Package trader;



Import Javax.ejb.EJBLocalHome;











Import javax.ejb.CreateException;



Public interface Userinfolocalhome extends Ejblocalhome {











Public userinfolocal Create () throws createexception;



Public userinfolocal Create (string userName, String userage,











String logintime) throws createexception;











}



OK, now that our EJB is ready to run, we will test this session Bean in the next section. (To be continued)












Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.