Examples of the three-layer structure of actual JBUILDER7 + JBOSS3 + SQL Server2000

zhaozj2021-02-08  227

Practical JBUILDER7 JBOSS3 SQL Server2000

Example of a complete three-layer structure

Liu Xiaowei: Liuxiaowei2000@sina.com

Introduction:

This article tells the implementation of the J2EE for establishing a typical 3-layer structure, mainly to implement the process, no theoretical instructions. This is completely written according to my personal experience, I hope to help everyone, welcome to a lot of criticisms!

Suppose JBuilder7 and JBoss3x are installed, the operating system is: Windows2000 Server (SP2), the database is: SQLServer2000 (SP2). JDBC is the driver of Microsoft SQLServer2000. Example source code: http://weisoft.myrice.com/download/jbossdemo.ra, (SQLServer SA password 9cbs)

One. Environment setting

1. Download and install JBossopentool for jbuilder 7http: //weisoft.myrice.com/download/jbuilder_jbossot.jar copies the downloaded JBossopentool.jar to jBuilder7's lib / ext directory, follow JBuilder.

1. Configure MS SQL Server 2000 JDBCJBOSS settings: Copy msbase.jar, msutil.jar, and mssqlserver.jar three files to JBoss's Server / default / lib directory. Copy the mssql-service.xml of JBoss DOCS / EXAMPLES / JCA directory to the server / default / deploy directory of jboss, and make the following modification: mssql-service.xml (red is The modification section is the database name, user name, password, according to your environmental adjustment): JDBC: Microsoft: SQLServer: // localhost : 1433; DatabaseName = northwind sa 9cbs MSSQL-XA-Service.xml (red is a modification section, is the SQLServer server name, database name): ServerName = localhost; DatabaseName = Northwind; SelectMethod = CURSOR jbuilder configuration: Select: Tools-> Enterprise Setup, click Add on the Database Drivers page, single in the pop-up dialog box Hit NEW, and fill in the name for the MS SQL Server JDBC, Location in the pop-up dialog box, click the Add button, select MSBase.jar, Msutil.jar, MSSQLServer.jar, click OK to close the current dialog, you can See the MS SQL Server JDBC has been added, click OK to close the current dialog, click OK again, and the configuration is complete. Rain from JBuilder 7.

2. Start JBUILDER7, select: Tools-> configure Servers Select the JBoss 3.x on the left, select the enable server on the right, follow the table information to fill in: General Page: Home Directiry = f: /jboss-3.0.4_tomcat-4.1. 12 // <- JBoss installation directory main class = org.jboss.mainvm parameters = -ms64m -mx64m -dprogram.name = Run.batserver parameters = -c defaultWorking Directory = f: /jboss-3.0.4_tomcat-4.1. 12 / Bincustom Page: JBoss Installation Directory = f: /jboss-3.0.4_tomcat-4.1.12 // <- JBoss installation directory Tomcat 4x jbuilder installation directory = f: /jbuilder7/jakarta-tomcat-4.0.3 // <- Tomcat installation directory jboss configuration to use = default Click OK. 3. Select Tools-> Configure Libraries, click the New button in the pop-up dialog box, fill in the JBoss Libs in the Name column, click the Add button, join the javax.servlet under the / server / default / lib directory in the JBoss directory. JAR and JBOSS-J2EE.JAR files, click OK.

two. Implementation steps

1. Create a new project: Select File-> New Project, fill in JBossDemo in the Name column, enter the save path in the Directory bar, others constant, click Finsih. Choose Project-> Project Properties, click the Add button in the Required Libraries in the Path page, select the JBoss Libs we just created in the pop-up dialog box, click OK. Select Server page, select Single Server for All Service in Project, select JBoss 3.x in the drop-down list, click OK.

2. New EJB Module: Select File-> New, select the EJB Module icon in the Enterprise page in the pop-up dialog box, click OK. In the pop-up dialog box, fill in JBossDemOModule, others unchange, click OK.

3. Newly built two CMP Right-click on Datasource in the lower left corner, select Import Schema from Database, fill in in the pop-up dialog box as follows: driver = com.microsoft.jdbc.sqlserver.sqlserDriverURURL = JDBC: Microsoft: SQLServer: / / localhost: 1433; DatabaseName = NorthwindUserName = sa // ßSQLServer username password = "" // ßSQLServer password JNDI name = java: / MSSQLDS add a DatabaseName = Northwind in the Extended properties in the selected item All Schemas and Views, click OK. Successful, a Java: / MSSQLDS item will appear in DataSource, click the number on the left, will expand, will see the table name. Right-click the Employees table, select CMP 2.0 Entity Bean, and right click on the OrderS table, select CMP 2.0 Entity Bean. 4. Establish a table relationship Right-click on the rectangle of the Employees table on the right, select Add-> Relationship, click to point to the rectangle representative ODERSS table, will see a line to connect two rectangles, while Employees Table has a more ORDERS field. Click the jbosscmp-jdbc page in the lower right corner, fill in the following, other unchanged: DataSource = mssqldsDataSource-mapping = hypersonic SQL Select File-> Save all to save items. Select Project -> "make Project JBossDemo.jpx" compile project.

5. Establish a session bean to right-click on the blank of the right, select Create EJB-> session bean, change bean name to getData, right-click Rectangle on behalf of this session bean, select Add-> Method, fill in: Method Name = getordersbyemployeesidReturn Type = VectorInput Parameters = INTEGER IDINTERFACE = Remote Select File-> Save ALL Save Item. Select Project -> "make Project JBossDemo.jpx" compile project.

6. Write the code Right-click on the rectangle of GetData, select View Bean Source. Add the following statement at the beginning: Import java.util. *; Import javax.naming. *; Fill in getOrDersbyemployeesid as follows:

Public Vector GetOrdersbyemployeesid (Integer ID)

{

Vector result = new vector ();

Result.Add (ID);

Try

{

Context ctx = new initialContext ();

Employeeshome Home = (EMPLOYEESHOME) CTX.lookup ("Employees"); Employees EMP = Home.FindByprimaryKey (ID);

Collection Orders = Emp.getRDERS ();

Iterator it = Orders.iterator ();

While (it.hasnext ())

{

ORDERS Order = (Orders) it.next ();

Result.add (Order.GetOrderId ());

}

}

Catch (Exception EX)

{

System.out.println ("ShowordersByemployeesid () error:" ex.getMessage ();

}

Return Result;

}

7. Establish a servlet

Select File-> New, select the servlet icon in the web page in the pop-up dialog box, click OK. In the pop-up dialog box, fill in the FormServlet, others unchange, click Next, select the doget () item, others constant, click Finish. Fill in FormServlet.java as follows: Public void doget (httpservletRequest Request, HttpservletResponse Response) Throws ServleTexception, IOException

{

Response.setContentType (Content_Type);

PrintWriter out = response.getwriter ();

Out.println ("

Enter the Employees Id ");

Out.println (" Enter Employees ID in The Input Fields Below. ");

out.println ( "

");

Out.println ("

");

Out.println ("Name
");

Out.println (" ");

out.println ( "



");

Out.print ("");

Out.println ("");

} Select File-> New again, select the servlet icon in the web page in the pop-up dialog box, click OK. In the pop-up dialog box, you fill in the ShowordersServlet, others constant, click Next, select the dopost () item, others unchange, click Next, click Next, click Add Parameter, click below: Name = EmployeeiDType = StringDesc = Employee's idVariable = EmployeEidDefault = 1 Click Next, click Finish. Fill in the ShowOrdersServlet.java by doPost () function: Do not forget to join at the beginning of the following statements:.. Import java.util *; import javax.naming *; public void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String Employeesid = Request.getParameter ("EmployeeID");

IF (EmployeesID == Null)

{

EmployeesID = "1";

}

Response.setContentType (Content_Type);

PrintWriter out = response.getwriter ();

Vector orders = new vector ();

Try

{

Context ctx = new initialContext ();

ShowDataHome Home = (showdataHome) CTX.lookup ("ShowData");

Showdata showdata = home.create ();

Orders = showdata.showordersbyemployeesid (New Integer (EMPLOYEESID));

}

Catch (Exception EX)

{

System.out.println ("ShowordersSrvlet dopost () error:" ex.getMessage ());

}

Iterator it = Orders.iterator ();

Out.println ("");

Out.println (" showordersservlet </ title> </ head>");</p> <p>Out.println ("<Body>");</p> <p>Out.println ("<p> ORDERS with EMPLOYEESID" Employeesid "</ P>");</p> <p>While (it.hasnext ())</p> <p>{</p> <p>Out.println ("<p> orderid =" it.next (). Tostring () "</ p>");</p> <p>}</p> <p>Out.println ("<H1> ORDER Count =" ORDERS.SIZE () "</ h1>");</p> <p>Out.println ("</ Body> </ HTML>");</p> <p>8. Establish an EAR file Right-click <Default Webapp> in the left directory tree, select Properties. Fill in the name of the WebApp page as JBossDemo, set all the items in the Dependencies page to Exclude All, click OK. Select File-> New, select the EAR icon in the Enterprise page in the pop-up dialog box, click OK. The first page is constant, click Next, select JBossDemOModule, click Next, click Next, click Next, select JBossDemo, click Finish. Select File-> Save all to save the project. Select Project -> "Rebuild Project JBossDemo.jpx" compile item.</p> <p>9. Publish the entire application Right-click JBossDemo.eargrp in the left directory tree, select Deploy Options for "JBossDemo.ear" -> Deploy, publish your application.</p> <p>10. Test application opens IE, enters http: // localhost: 8080 / jbossdemo / formservlet, Enter 3 in the edit box, click "Submit" in the edit box.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-2769.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="2769" 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.036</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 = 'MOGPAYdHQctlQfSEE5LZw2dCO3QCYqSnquRHc2kLt0pN_2BBDtW1ru6lnjEH0lOU1YMCWa_2Bb9JFJIXNkLgonxbDQ_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>