Develop web applications with JBuilder2005

xiaoxiao2021-03-06  78

Develop web applications with JBuilder2005

Gaoke Hua

JBuilder is an open Java IDE that integrates Tomcat, WebLogic. Although JDK, Tomcat, WebLogic continues to upgrade, we can still use their latest versions in JBuilder. Since the TOMCAT server is complicated, the programmers who are used to the Windows platform are often confused for Tomcat. This article gives an example of a database connection pool Database Connection Pool (DBCP) in the Tomcat environment, which illustrates the general steps for developing web applications with JBuilder and answers some of the frequent problems.

The JBUILDER2005 version of JDK is 1.4.2_04-b05, and its file is placed under the directory jbuilder_home / jdk1.4, the latest version of Tomcat is 5.0.27, its file is placed on the directory jbuilder_home / thirdParty / Jakarta-Tomcat-5.0.27 under. The following will first give an example of a database connection pool Database Connection Pool (DBCP) using the Tomcat environment.

1. File-New Project New Project Document, Enter Project File Name MYWEB and Directory C: / MyWeb

2. Project-Project Properties Set the properties of the project file, select Tomcat to the server

3. File-New New Web Module (WAR)

Enter the name of the Web Module DBTEST and Directory DBTest

4. File-new JSP, enter the name of the JSP file Test.jsp, and modify the contents of Test.jsp after the test.jsp file

Test.jsp:

<% @ Page ContentType = "Text / HTML; Charset = BIG5"%>

DB Test </ Title></p> <p></ hEAD></p> <p><body></p> <p><%</p> <p>Foo.dbtest TST = New foo.dbtest ();</p> <p>TST.INIT ();</p> <p>%></p> <p><H2> Results </ h2></p> <p>FOO <% = TST.GETFOO ()%> <br/></p> <p>Bar <% = TST.GetBar ()%></p> <p></ body></p> <p></ html></p> <p>A Runtime Configuration named Test will be generated.</p> <p>The Run-Configurations-Edit can modify the Runtime Configuration, especially if you specify the port number of the server and whether it is automatically searched as the port occupied.</p> <p>5. File-new class, enter the class DBTEST and package name foo, modify its content after the dbtest.java file is generated</p> <p>Dbtest.java</p> <p>Package foo;</p> <p>Import javax.naming. *;</p> <p>Import javax.sql. *;</p> <p>Import java.sql. *;</p> <p>Public class dbtest {</p> <p>String foo = "not connection";</p> <p>INT bar = -1;</p> <p>Public void init () {</p> <p>Try {</p> <p>Context ctx = new initialContext ();</p> <p>IF (ctx == null)</p> <p>Throw New Exception ("Boom - No Context");</p> <p>DataSource DS = (Datasource) CTX.lookup</p> <p>"Java: Comp / Env / JDBC / TESTDB");</p> <p>IF (ds! = null) {</p> <p>Connection conn = ds.getConnection ();</p> <p>IF (conn! = null) {</p> <p>Foo = "Got Connection" Conn.toT7tring ();</p> <p>Statement Stmt = conn.createstatement ();</p> <p>ResultSet RST =</p> <p>Stmt.executeQuery</p> <p>"SELECT ID, FOO, BAR from TestData";</p> <p>IF (Rst.Next ()) {</p> <p>Foo = RST.GetString (2);</p> <p>Bar = Rst.Getint (3);</p> <p>}</p> <p>CONN.CLOSE ();</p> <p>}</p> <p>}</p> <p>} catch (exception e) {</p> <p>E.PrintStackTrace ();</p> <p>}</p> <p>}</p> <p>Public string getfoo () {return foo;}</p> <p>Public int getbar () {return bar;}</p> <p>}</p> <p>6. Modify the content of web.xml</p> <p>Web.xml:</p> <p><? XML Version = "1.0" encoding = "UTF-8"?></p> <p><web-app xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/xmlschema-instance" xsi: schemAlocation = "http : //java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd "Version =" 2.4 "></p> <p><Description> MySQL Test App </ description></p> <p><resource-ref></p> <p><Description> DB Connection </ Description></p> <p><res-ref-name> JDBC / TESTDB </ RES-REF-NAME></p> <p><Res-Type> javax.sql.datasource </ res-Type></p> <p><res-auth> container </ res-auth></p> <p></ resource-ref></p> <p></ web-app></p> <p>7. F9 running the app, the Tomcat subdirectory will be generated in the MyWeb directory, which contains the conf subduial directory.</p> <p>Generate dbtest.xml files in Tomcat_Home / Conf / Catalina / LocalHost directory</p> <p>8. Add file server8080.xml in myWeb / Tomcat / conf directory to the project file, modify the content of Server8080.xml</p> <p>Server8080.xml:</p> <p><? XML Version = "1.0" encoding = "UTF-8"?></p> <p><Server debug = "0" port = "8081" shutdown = "shutdown"></p> <p><Service name = "Catalina"></p> <p><Connector AcceptCount = "10" ConnectionTIMEOUT = "60000" Debug = "0" Maxthreads = "75" MINSPARETHREADS = "5" port = "8080" /> <engine debug = "0" defaultHost = "localhost" name = "Catalina "></p> <p><Host appbase = "c: / myweb / tomcat / webapps" autodeploy = "false" debug = "0" deployxml = "false" name = "localhost" unpackwars = "false">> FALSE</p> <p><Context path = "/ dbtest" DOCBASE = "c: / myweb / dbtest" debug = "5" reloadable = "true" crosscontext = "true" Workdir = "c: / myweb / tomcat / work / dbtest"></p> <p><Logger classname = "org.apache.catalina.logger.filelogger" prefix = "localhost_dbtest_log." Suffix = ". Txt" TimeStamp = "true" /></p> <p><Resource Name = "JDBC / TESTDB" Auth = "Container" type = "javax.sql.datasource" /></p> <p><ResourceParams Name = "JDBC / TestDB"></p> <p><parameter></p> <p><name> factory </ name></p> <p><value> org.apache.commons.dbcp.basicDataSourceFactory </ value></p> <p></ parameter></p> <p><! -</p> <p>Maximum Number of DB Connections in pool. Makess</p> <p>Configure your mysqld max_connections large enough to handle</p> <p>All of Your DB Connections. Set to 0 for no limit.</p> <p>-></p> <p><parameter></p> <p><name> maxactive </ name></p> <p><Value> 100 </ value></p> <p></ parameter></p> <p><! -</p> <p>Maximum Number of iDLE DB Connections To retain in pool.</p> <p>Set to 0 for no limit.</p> <p>-></p> <p><parameter></p> <p><name> maxidle </ name></p> <p><Value> 30 </ value></p> <p></ parameter></p> <p><! -</p> <p>Maximum Time to Wait for A DB Connection To Become Availablein MS, IN this Example 10 seconds. AN Exception is throwniff</p> <p>THIS TIMEOUT IS EXCEEDED. SET to -1 to wait indefinitely.</p> <p>-></p> <p><parameter></p> <p><name> maxwait </ name></p> <p><Value> 10000 </ value></p> <p></ parameter></p> <p><! - MySQL DB Username and Password for DB Connections -></p> <p><parameter></p> <p><name> Username </ name></p> <p><value> sa </ value></p> <p></ parameter></p> <p><parameter></p> <p><name> Password </ name></p> <p><value> TopComputer </ value></p> <p></ parameter></p> <p><! - Class Name for mm.mysql jdbc driver -></p> <p><parameter></p> <p><name> driverclassname </ name></p> <p><value> com.microsoft.jdbc.sqlser.sqlserverdriver </ value></p> <p></ parameter></p> <p><! -</p> <p>The JDBC Connection Url for Connecting to your My My Mysql DB.</p> <p>The autoreconnect = true argument to the url makess sure what the the URL MAKES SURE THAT</p> <p>MM.MYSQL JDBC Driver Will Automatically Reconnect IF MySQLD CLOSED THE</p> <p>Connection. mysqld by Default Closes iDle Connections After 8 Hours.</p> <p>-></p> <p><parameter></p> <p><name> URL </ name></p> <p><value> JDBC: Microsoft: SQLSERVER: // NT04: 1433; DatabaseName = Test </ value></p> <p></ parameter></p> <p></ Resourceparams></p> <p></ Context></p> <p></ Host></p> <p></ Engine></p> <p></ Service></p> <p></ Server></p> <p>9. Put the JDBC drive in a C: /borland/jakarter2005/thirdparty/jakarta-tomcat-5.0.27/common/lib directory</p> <p>10. Create a database TEST in SQL Server, Database Table File TestData</p> <p>CreatTable.sql:</p> <p>IF exists (select * from dbo.sysObjects where id = Object_id (n '[dbo]) And ObjectProperty (id, n'susertable') = 1)</p> <p>Drop Table [DBO]. [TestData]</p> <p>Go</p> <p>Create Table [DBO]. [TestData] (</p> <p>[ID] [int] Not null,</p> <p>[foo] [varchar] (50) collate chinese_taiwan_stroke_ci_as null, [bar] [int] not null</p> <p>) On [primary]</p> <p>Go</p> <p>Enter several records as test data.</p> <p>11. f9</p> <p>12. Create a batch file in C: / MyWebmulu Startup.bat and shutdown.bat contents are as follows:</p> <p>Startup.bat:</p> <p>C: /borland/jbuilder2005/jdk1.4/bin/javaw -classpath "c: /borland/jbuilder2005/thirdparty/jakarta-tomcat-5.0.27/bin/bootstrap.jar; c: /borland/jbuilder2005/jdk1.4 /LIB/Tools.jar "" -dcatalina.home = c: /borland/jbuilder2005/thirdparty/jakarta-tomcat-5.0.27 "Org.apache.catalina.startup.bootstrap -config" c: / myweb / tomcat / confected /server8080.xml "Start</p> <p>Shutdown.bat:</p> <p>C: /borland/jbuilder2005/jdk1.4/bin/javaw -classpath "c: /borland/jbuilder2005/thirdparty/jakarta-tomcat-5.0.27/bin/bootstrap.jar; c: /borland/jbuilder2005/jdk1.4 /LIB/Tools.jar "" -dcatalina.home = c: /borland/jbuilder2005/thirdparty/jakarta-tomcat-5.0.27 "Org.apache.catalina.startup.bootstrap -config" c: / myweb / tomcat / confected /server8080.xml "stop</p> <p>13. Run Startup.bat, enter http:// localhost: 8080 / dbtest / test.jsp: // localhost: 8080 / dbtest / test.jsp</p> <p>How to deploy web applications?</p> <p>1. Package the generated WAR file</p> <p>2. Copy dbtest.war to tomcat_home / webApps</p> <p>3. Create file dbtest.xml in tomcat_home / conf / catalina / localhost directory</p> <p>Dbtest.xml</p> <p><! -</p> <p>Context Configuration File for the Tomcat Administration Web APPP</p> <p>$ ID: admin.xml, v 1.2 2002/07/23 12:13:05 REMM EXP $</p> <p>-></p> <p><Context path = "/ dbtest" DOCBASE = "/ dbtest" debug = "5" reloadable = "true" crosscontext = "true" workdir = "../ Work / dbtest"></p> <p><Logger classname = "org.apache.catalina.logger.filelogger" prefix = "localhost_dbtest_log." Suffix = ". Txt" TimeStamp = "true" /></p> <p><Resource name = "jdbc / testdb" auth = "container" type = "javax.sql.datasource" /> <resourceParams name = "jdbc / testdb"></p> <p><parameter></p> <p><name> factory </ name></p> <p><value> org.apache.commons.dbcp.basicDataSourceFactory </ value></p> <p></ parameter></p> <p><! -</p> <p>Maximum Number of DB Connections in pool. Makess</p> <p>Configure your mysqld max_connections large enough to handle</p> <p>All of Your DB Connections. Set to 0 for no limit.</p> <p>-></p> <p><parameter></p> <p><name> maxactive </ name></p> <p><Value> 100 </ value></p> <p></ parameter></p> <p><! -</p> <p>Maximum Number of iDLE DB Connections To retain in pool.</p> <p>Set to 0 for no limit.</p> <p>-></p> <p><parameter></p> <p><name> maxidle </ name></p> <p><Value> 30 </ value></p> <p></ parameter></p> <p><! -</p> <p>Maximum Time to Wait for A DB Connection To Become Available</p> <p>IN ms, in this example 10 seconds. An Exception Is Thrown IF</p> <p>THIS TIMEOUT IS EXCEEDED. SET to -1 to wait indefinitely.</p> <p>-></p> <p><parameter></p> <p><name> maxwait </ name></p> <p><Value> 10000 </ value></p> <p></ parameter></p> <p><! - MySQL DB Username and Password for DB Connections -></p> <p><parameter></p> <p><name> Username </ name></p> <p><value> sa </ value></p> <p></ parameter></p> <p><parameter></p> <p><name> Password </ name></p> <p><value> TopComputer </ value></p> <p></ parameter></p> <p><! - Class Name for mm.mysql jdbc driver -></p> <p><parameter></p> <p><name> driverclassname </ name></p> <p><value> com.microsoft.jdbc.sqlser.sqlserverdriver </ value></p> <p></ parameter></p> <p><! -</p> <p>The JDBC Connection Url for Connecting to your My My Mysql DB.</p> <p>The autoreconnect = true argument to the url makess supething</p> <p>Connection. mysqld by Default Closes iDle Connections After 8 Hours.</p> <p>-></p> <p><parameter></p> <p><name> URL </ name></p> <p><value> JDBC: Microsoft: SQLSERVER: // NT04: 1433; DatabaseName = Test </ value></p> <p></ parameter></p> <p></ Resourceparams></p> <p></ Context></p> <p>4. Start Tomcat, dbtest.war will decompress Tomcat_Home / WebApps / Dbtest, and generate dbtest directories in Tomcat_Home / Work / Catalina / LocalHost directory</p> <p>Why can't I generate a WAR file?</p> <p>Set the properties related to Build Web Archive in the Proterties for Web Module dialog.</p> <p>How do I join directory and files in a web application?</p> <p>Right-click Module Directory, select New-Directory in the pop-up menu, enter the directory name; or right-click on the directory to create the file, select New-file in the pop-up menu, select the file type, and enter the file name. Note that this added file can only be the specified file type. The directory and files thus added will be packaged into the WAR file.</p> <p>How to add other types of files?</p> <p>You can copy the file to the specified directory, set the properties Content in the Proterties for Web Module dialog, select Include All Classes and Resources, which can also package the added file into the WAR file.</p> <p>How to use the specified JDK?</p> <p>Select Menu Tools-Configure-JDKS, press the New button in the pop-up dialog box and select the path to the JDK.</p> <p>Select Menu Project-Project Properties, select Add JDK in the pop-up dialog box.</p> <p>How to use the specified Tomcat?</p> <p>Select Menu Enterprise-Configure Servers, select Tomcat5.0 in the pop-up dialog box, press the COPY button,</p> <p>Select Copy's Server Copy Of Tomcat 5.0, select Home Directory</p> <p>Select Menu Project-Project Properties, set attribute Server in the pop-up dialog, select the join Tomcat server</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-107486.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="107486" 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.043</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 = 'q5ZlGa_2Bvn9IA0nxo_2BuI3Xcw_2FJOmfBaGAdHSVCFkTr7Fjy9nkxqMt12aMgs8vgAh3Zy74k1XV50hvaFBnnEquIA_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>