How to use JBuilder2005 to develop Web applications

Source: Internet
Author: User
Tags auth connect sql mysql string stmt version port number
The web| program JBuilder is an open Java IDE that integrates servers such as Tomcat, WebLogic, and so on. Although JDK, Tomcat, and WebLogic are constantly upgraded, we can still use their latest version in JBuilder. Because the configuration of Tomcat servers is more complex, programmers accustomed to Windows platforms are often puzzled by the use of Tomcat.

This paper presents an example of database Connection pool (DBCP) in a Tomcat environment, illustrates the general steps of using JBuilder to develop Web applications, and answers some of the frequently encountered problems.

JBuilder2005 's version of the JDK is 1.4.2_04-b05, whose files are placed under the directory jbuilder_home\jdk1.4, and the latest version of Tomcat is 5.0.27, with files in the directory jbuilder_home\ Thirdparty\ jakarta-tomcat-5.0.27 under the sun. The following is an example of a database Connection pool (DBCP) using a tomcat environment.

1. File-new Project new project file, input project file name MyWeb and directory C:\myWeb

2. Project-project properties set the attributes of the project file, select Tomcat as the server

3. File-new new Web Module (WAR)

Enter the name dbtest and directory dbtest for Web module

4. File-new new JSP, input JSP file name test.jsp, produce test.jsp file modify test.jsp content:

       
        
         
        test.jsp:<%@ page contenttype= "text/html; Charset=big5 "%>   
          DB Test    <%foo. Dbtest TST = new Foo. Dbtest (); Tst.init (); %> Results Foo <%= tst.getfoo ()%> 
         
Bar <%= tst.getbar ()%>

A runtime configuration called test will be generated. Select Run-configurations-edit to modify runtime configuration, in particular, you can specify the port number of the server and whether to automatically search for the ports that are occupied.

5. File-new class, type name dbtest and package name foo, produce Dbtest.java file and modify its contents

 
       
         dbtest.javapackage foo;import ja Vax.naming.*;import javax.sql.*;import java.sql.*;p ublic class dbtest{String foo = ' not Connected '; 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 rst =stmt.executequery ("SELECT ID, foo, bar from TestData");       if (Rst.next ()) {foo=rst.getstring (2);      Bar=rst.getint (3);     } conn.close ();   }}catch (Exception e) {e.printstacktrace ();
     Public String Getfoo () {return foo.} public int Getbar () {return bar;}} 
       
6. Modify the Web. Content of XML

       
        
         
        Web.xml:
         
          
          
            MySQL Test app 
           
           
           
             DB  Connection 
            
           
             jdbc/testdb 
            
           
             javax.sql.DataSource 
            
           
             Container 
            
           
         
       
        


7. F9 run the application, the Tomcat subdirectory will be generated in the MyWeb directory, which contains the Conf subdirectory, and Dbtest.xml files are generated in the Tomcat_home\conf\catalina\localhost directory.

8. Add the file in the myweb\tomcat\conf directory Server8080.xml to the project file and modify the Server8080.xml content:

       
        
  Server8080.xml:<?xml version= "1.0" encoding= "UTF-8" ><server debug= "0" port= "8081" shutdown= "Shutdown" ><service name = "Catalina" > <connector acceptcount= "Ten" connectiontimeout= "60000" debug= "0" maxthreads= "a" minsparethreads= "5" Port = "8080"/> <engine debug= "0" defaulthost= "localhost" name= "Catalina" > 
9. Place the JDBC driver in the C:\Borland\JBuilder2005\thirdparty\jakarta-tomcat-5.0.27\common\lib directory

10. Set up Database test in SQL Server, database table file TestData

       
        
         
        CREATTABLE.SQL:IF exists (SELECT * from dbo.sysobjects WHERE id = object_id (N ' [dbo].[ TestData] and OBJECTPROPERTY (ID, N ' isusertable ') = 1) drop table [dbo]. [TestData] Gocreate TABLE [dbo]. [TestData] ([ID] [int] NOT NULL, [foo] [varchar] (m) COLLATE chinese_taiwan_stroke_ci_as null, [bar] [int] NOT NULL) on [PRIMARY ]go
       
        

Enter a few records as test data.

F9.

12. The contents of the Startup.bat and Shutdown.bat for the establishment of batch documents in C:\myWebmulu 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\conf\server8080. XML "Startshutdown.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\conf\server8080.xml "Stop"
       
        

13. Run Startup.bat, enter Http://localhost:8080/DBTest/test.JSP in browser

How do I deploy a Web application?

1. Pack and build the war file

2. Copy Dbtest.war to Tomcat_home\webapps

3. Create a file in the Tomcat_home\conf\catalina\localhost directory Dbtest.xml

       
        
dbtest.xml<!--Context configuration file for the Tomcat administration Web app$id:admin.xml,v 1.2 2002/07/23 12:13:05 R Emm Exp $--><context path= "/dbtest" docbase= "/dbtest" debug= "5" reloadable= "true" crosscontext= "true" workdir= ". /work/dbtest "><logger classname=" Org.apache.catalina.logger.FileLogger "prefix=" Localhost_dbtest_log. "suffix=". TXT "timestamp=" true "/><resource name=" Jdbc/testdb "auth=" Container "type=" Javax.sql.DataSource "/><resourceparams Name= "Jdbc/testdb" > <parameter> <name> Factory </name> <value> org.apache.commons.dbcp.basicdatasourcefactory</ value> </parameter>!--Maximum number of DB connections in pool. Make sure your configure your MySQLd max_connectionslarge enough to handle all of your DB connections. Set to 0 for no limit. --> <parameter> <name> maxactive </name> <value> </value> </parameter>!--Maximum number of idle dbconnections to RET  Ain in Pool. Set to 0 for no limit. --> <parameter> <name> maxidle </name> <value> </value> </parameter>!--MAximum a DB connection to become available in MS, example. An Exception is thrown if it timeout is exceeded. Set to-1 to wait indefinitely. --> <parameter> <name> maxwait </name> <value> 10000 </value> </parameter>!--MySQL dB username Andpassword for DB Connect Ions--> <parameter> <name> username </name> <value> sa </value> </parameter> <parameter> <name> password </name> <value> top Computer </value> </parameter>!--Class name for mm.mysql JDBC driver--> <parameter> <name> driverclassname </name> <val  Ue>com.microsoft.jdbc.sqlserver.sqlserverdriver </value> </parameter>!--the JDBC connection URL for connecting to your  MySQL DB.  The autoreconnect=true argument to the URL makes sure this mm.mysql JDBC Driver would automaticallyreconnect if mysqld closed the connection. Mysqld By default Closesidle connections after 8 hours. --> <parameter> <name> url </name> <value> jdbc:microsoft:sqlserver://nt04:1433;databasename=test </value> </ parameter></ResourceParams> </Context> 
       

4. Start Tomcat,dbtest.war will extract to Tomcat_home\webapps\dbtest and generate DBTest directory in Tomcat_home\work\catalina\localhost directory

Why can't I generate a war file?

Set the build-related property build Web archive in the Proterties for Web Module dialog box.

How do I add directories and files to a Web application?

Right-click the module directory, select New-directory from the pop-up menu, enter the directory name, or right-click the directory where you want to create the file, select New-file in the pop-up menu, select a file type, and enter a filename. Note that the file you are adding can only be a specified file type. The directories and files that are added are packaged into the war file.

How do I add other types of files?

You can copy the file to the specified directory, set the property content in the Proterties for Web Module dialog box, select Include all classes and resources, and then package the joined files into the war file.

How do I use the specified JDK?

Select Menu Tools-configure-jdks, press the New button in the pop-up dialog box, and then select the JDK path.

Select Menu Project-project Properties and select the JDK to join in the pop-up dialog box.

How do I use the specified tomcat?

Select the menu enterprise-configure Servers, select Tomcat5.0 in the pop-up dialog box, and press the Copy button.

Select the server copy of copy of Tomcat 5.0, select Home Directory

Select Menu Project-project Properties, set property Server in the pop-up dialog box, select the joined Tomcat server



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.