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"%>
<% Foo.dbtest TST = new foo.dbtest (); tst.init ();%>
body> html>
A Runtime Configuration named Test will be generated. 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.
5. File-new class, enter the class name dbtest and package Foo, and modify its contents after dbtest.java files DBTest.java package foo;
Import javax.naming. *; import javax.sql. *; import java.sql. *;
Public class dbtest {
String foo = "not connection"; int BAR = -1;
Public void init () {try {context ctx = new initialContext (); if (ctx == null) throw new exception ("Boom - No Context"); DataSource DS = (Datasource) CTX.lookup ("Java: Comp / ENV / JDBC / TESTDB ");
IF (ds! = null) {connection conn = ds.getConnection ();
IF (conn! = null) {foo = "got connection" conn.tostring (); statement stmt = conn.createstatement (); resultset = stmt.executeQuery ("SELECT ID, FOO, BAR from TestData); if (RST.NEXT ()) {foo = Rst.getstring (2); bar = rst.getint (3);} conn.close ();}}} catch ()}}} catch ()}} catch ()}}
Public string getfoo () {return foo;} public int getbar () {return bar;}}
6. Modify the content of web.xml
Web.xml: XML Version = "1.0" encoding = "UTF-8"?>
7. F9 running the application, the Tomcat subdirectory will be generated in the MyWeb directory, which contains the conf subduial, generated in the tomcat_home / conf / catalina / localhost directory 8. Will the MyWeb / Tomcat / Conf directory Document Server8080.xml joins the project file, modify the content of Server8080.xml
Server8080.xml:
XML Version = "1.0" encoding = "UTF-8"?>
! -. Maximum number of dB connections in pool Make sure you configure your mysqld max_connections large enough to handle all of your db connections Set to 0 for no limit -..>
/ Parameter> <-!. The JDBC connection url for connecting to your MySQL dB The autoReconnect = true argument to the url makes sure that the mm.mysql JDBC Driver will automatically reconnect if mysqld closed the connection mysqld by default closes idle connections. After 8 Hours. ->
10. Create a database TEST in SQL Server, Database Table File TestData
CreatTable.sql:
IF exists (select * from dbo.sysObjects where id = Object_id (n '[dbo]) And ObjectProperty (id, n'susertable') = 1)
Drop Table [DBO]. [TestData]
Go
Create Table [DBO]. [TestData] (
[ID] [int] Not null,
[foo] [varchar] (50) collate chinese_taiwan_stroke_ci_as null,
[bar] [int] Not null
) On [primary]
Go
Enter several records as test data.
11. f9
12. Create a batch file in C: / MyWebmulu Startup.bat and shutdown.bat contents are as follows:
Startup.bat:
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
Shutdown.bat:
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 "STOP13. Run Startup.bat, enter http:// localhost: 8080 / dbtest / test.jsp: // localhost: 8080 / dbtest / test.jsp.bat
How to deploy web applications?
1. Package generation WAR file 2. Copy dbtest.war to Tomcat_home / WebApps 3. Create file dbtest.xml dbtest.xml
/ Name>
Why can't I generate a WAR file?
Set the properties related to Build Web Archive in the Proterties for Web Module dialog.
How do I join directory and files in a web application?
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.
How to add other types of files?
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.
How to use the specified JDK?
Select Menu Tools-Configure-JDKS, press the New button in the pop-up dialog box and select the path to the JDK. Select Menu Project-Project Properties, select Add JDK in the pop-up dialog box.
How to use the specified Tomcat?