选择显示字体大小

利用jbuilder2005开发web应用程序


  jbuilder是一个开放的java ide,它集成了tomcatweblogic服务器。虽然jdk、tomcatweblogic不断升级,我们仍可以在jbuilder中使用它们的最新版本。由于tomcat服务器的配置比较复杂,习惯了windows平台的程序员常常对tomcat的使用感到困惑。 本文给出了一个使用tomcat环境下的数据库连接池database connection pool (dbcp) 的例子,说明了用jbuilder开发web应用的一般步骤,并回答了一些经常遇到的问题。

  jbuilder2005所带jdk的版本是1.4.2_04-b05,其文件放在目录jbuilder_home\jdk1.4下,tomcat的最新版本是5.0.27,其文件放在目录jbuilder_home\thirdparty\ jakarta-tomcat-5.0.27下。下面首先给出给出了一个使用tomcat环境下的数据库连接池database connection pool (dbcp) 的例子。

  1. file-new project新建工程文件,输入工程文件名称myweb和目录c:\myweb

  2. project-project properties设置工程文件的属性,选择tomcat服务器

  3. file-new新建web module(war)

  输入web module的名称dbtest和目录dbtest

  4. file-new新建jsp,输入jsp文件的名称test.jsp,产生test.jsp文件后修改test.jsp的内容

  test.jsp:

<%@ page contenttype="text/html; charset=big5" %>
html
<head>
 <title>db test</title>
</head>
<body>
 <%
  foo.dbtest tst = new foo.dbtest();
  tst.init();
 %>
 <h2>results</h2>
 foo <%= tst.getfoo() %>

 bar <%= tst.getbar() %>
</body>
</html

  将会生成一个名称为test的runtime configuration。

  选run-configurations-edit可修改runtime configuration,特别是可以指定服务器的端口号和是否自动搜索为被占用的端口。

  5. file-new class,输入类名dbtest和包名foo,产生dbtest.java文件后修改它的内容

dbtest.java

package foo;

import javax.naming.*;
import javax.sql.*;
import java.sql.*;
public 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. 修改web.xml的内容

  web.xml:

<?xml version="1.0" encoding="utf-8"?>

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">

 <description>mysql test app</description>
 <resource-ref>
  <description>db connection</description>
  <res-ref-name>jdbc/testdb</res-ref-name>
  <res-type>javax.sql.datasource</res-type>
  <res-auth>container</res-auth>
 </resource-ref>
</web-app>


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons