Development sessionbean

xiaoxiao2021-03-05  51

A few steps below:

1 Establish a test web module

2 Establish an IDEA EJB module to write EJB

3 compile, package

4 write test page

5 Release EJB, Web Test Module, Test EJB

1 Create a web test module.

In the default user_projects / domains / mydomain / applications directory, create a folder called web. This folder is our Web module we test EJB.

Create a new Web-INF folder under the web folder, create a new LIB folder under Web-INF.

New web.xml files under Web-INF, as follows:

OK. The web test module is completed.

2 Establish an IDEA EJB module to write EJB

Open IDEA, select File-New-EJB Modules, change the module name to "EJBSAMPLES", as shown below:

In the server option, select WebLogic, and the rest is set by default. Finally finish.

New package under the SRC folder. The name is as follows: com.diegoyun.ejb.slb, as shown below:

Put your mouse on the module name, right, select: New-sessionBean. Then set the following attribute box in the pop-up:

: Enter helloworld

Package: Select / Enter com.diegoyun.ejb.slb

The remaining information IDEA will help you automatically set, the entire property box property is as follows:

Click OK to end

At this time, the attribute configuration interface of the EJB will pop, as follows:

In Display Name, enter HelloWorldejb

Then switch to the WebLogic Server page, enter JNDI NAME as follows: EJB / Session / HelloWorldejb

The interface is as follows:

Close this property page. Idea has helped you write the configuration information of EJB. You can open the EJB-JAR.XML and WebLogic-EJB-JAR.XML of META-INF /.

At this time, there should be three files under com.diegoyun.ejb.slb: HelloWorld, HelloWorldbean and HelloWorldHome

Add a method to the HelloWorld interface as follows:

Public interface helloworld extends ejbobject {

Public String getGreeting (String Name) throws RemoteException;

}

Add a method to the HelloWorldBean interface as follows:

Public class helloworldbean imports sessionbean {

...............

// omit ivit

Public string getGreeting (string name) {

Return "Hello," Name;

}

}

OK. Your HelloWord EJB is already written.

3 Compile, package, release EJB this example uses a web way to access EJB. And did not pack the Web module and EJB JAR into EAR. So I must first compile the EJB source to JAR, release this JAR, then copy it to the lib directory of the test web module so that the web page can access bean.

This example uses ANT scripts to perform commands such as compilation and packaging. Create a build.xml script under the Idea's EJBSAMPLES module, as follows:

Destdir = "$ {build}" incrudes = "** / *. java" />

To install the installation of your machine WebLogic, modify the following information:

: Since this example is compiled by WebLogic.jar, the position of the JAR must be known. Typically, it is located in / WebLogic81 / Server / LIB /. For example, if your WebLogic is installed in the C drive, then your JAR should set this:

: WebLogic places the directory of the upload file. Usually located in the / User_Projects / Domains / / / upload folder. If you use a WebLogic default installation, "Your Domain> is usually MyDomain (created by WebLogic), is usually MyServer. For example, if your WebLogic is installed in the C drive, and Domain and Server use the default, the property is set as follows:

: The lib directory of the web test module. Follow you your own native configuration.

At this point, the preparation of EJB is completed. Run the script just now.

Ant build.xml

Then check if there is an EJB jar under the web test module / web-inf / lib, whether there is an EJB JAR in the weblogic UPLOAD directory. If not, please check your configuration in the following steps.

4 write test page for testing

In the web module, create a new Hello.jsp, the content is as follows:

<% @ page language = "java"%>

<% @ page import = "com.diegoyun.ejb.slb.helloWorld,

com.diegoyun.ejb.slb.helloworldhome,

Javax.ejb. *,

Java.math. *,

Javax.naming. *,

Javax.rmi.PortableRemoteObject,

Java.rmi.RemoteException "%>

Hello </ Title></p> <p></ hEAD></p> <p><body bgcolor = "white"></p> <p><h1> <b> <center> stateless bean example </ center> </ b> </ h1></p> <p><hr></p> <p><form name = "frM" method = "post" action = "hello.jsp"></p> <p><Input Type = "text" value = "diego" name = "myname" /></p> <p><Input Type = "Submit" value = "submit" /></p> <p></ form></p> <p><p></p> <p><p> see: </ p></p> <p><br></p> <p><%</p> <p>HelloWorld Hello = NULL;</p> <p>String name = NULL;</p> <p>Name = Request.getParameter ("MyName");</p> <p>IF (name! = null &&! "" "" "Equals (name)) {TRY {</p> <p>InitialContext IC = New InitialContext ();</p> <p>Object objref = Ic.lookup ("ejb / session / helloworldejb");</p> <p>HelloWorldHome Home = (HelloWorldHome) PortableRemoteObject.narrow (Objref, HelloWorldHome.Class);</p> <p>Hello = home.create ();</p> <p>} catch (remoteexception ex) {</p> <p>System.out.println ("COULDN '' Create Hello Bean." EX.GETMESSAGE ());</p> <p>} catch (createException ex) {</p> <p>System.out.println ("COULDN '' Create Hello Bean." EX.GETMESSAGE ());</p> <p>} catch (namingexception ex) {</p> <p>System.out.println ("Unable to lookup home:" "HelloWorldHome" ex.getMessage ());</p> <p>}</p> <p>}</p> <p>IF (Hello! = null &&! "" "" "Equals (Hello) {</p> <p>String s = hello.getgreeting (name);</p> <p>OUT.PRINT (S);</p> <p>}</p> <p>%></p> <p></ body></p> <p></ html></p> <p>5 Release EJB, Web Test Module, Debug EJB</p> <p>Publish EJB. Start WebLogic Server and open the console.</p> <p>Then in the EJB publish page, select the JAR under the UPLOAD folder to publish, the default path should be: <bea DireTory> / user_projects / domains / mydomain / myserver / upload</p> <p>Release web module</p> <p>Under Deploy Web Application Modules, you can see our build web module under <BEA DIRETORY> / User_Projects / Domains / MYDOMAIN / Applications. Point "Target Module" is released, named "Web" name</p> <p>OK. All work has been completed!</p> <p>Open the browser, type: http: // localhost: 7001 / web / hello.jsp</p> <p>Click Submit, you can see Hello words.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-34612.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="34612" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.041</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '3dTfvs_2F_2Ff3Ut4G8bHTD6Krj_2BxpPKJROQhKNyxfKBuSvQo5SNMRIL2QEroqCB3CwG3Bz2sSfTveEbybhBtqL0eA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>