学习J2EE

学习J2EE第一天(了解掌握J2EE的大致结构)

J2EE Tutorial14

从今天起,我要按照Sun的在线文档的思路学习J2EE.
Good Luck!

J2EE Tutorial14总体分为4大块:

一、Java XML
处理xml文档以及实现web服务组件
# The Java API for XML Processing (JAXP)
# The Java API for XML-based RPC (JAX-RPC)
# SOAP with Attachments API for Java (SAAJ)
# The Java API for XML Registries (JAXR)

二、web-tier
j2ee的表现层或单独的web程序
# Java Servlet
# JavaServer Pages (JSP)
# JavaServer Pages Standard Tag Library (JSTL)
# JavaServer Faces
# web application internationalization and localization

三、Enterprise JavaBeans (EJB)
在J2EE程序中用来处理事物逻辑的组件
# Session beans
# Entity beans
# Message-driven beans
# Enterprise JavaBeans Query Language

四、platform services
J2EE用到的系统服务
# Transactions
# Resource connections
# Security
# Java Message Service

一些名词:
J2EE Containers
    J2EE server
    J2EE服务器,提供了EJB容器和web容器.

    Enterprise JavaBeans(EJB) container
    运行在J2EE服务器上,为J2EE程序管理和运行enterprise beans.

    Web container
    运行在J2EE服务器上,为J2EE程序管理和运行JSP页面和servlet组件.

    Application client container
    运行在客户机器上,管理和运行客户程序.

    Applet container
    运行在客户机器上,执行applet.

Web Services Support
    XML
    SOAP Transport Protocol
    客户请求和web服务回应是由Simple Object Access Protocol(SOAP)通过http协议在主机和客户机器之间交换数据.

WSDL Standard Format
    The Web Services Desription Language(WSDL)是一种标准的XML格式来描述web服务.

UDDI and ebXML Standard Formats
    其它的以XML为基础的标准.
    Universal Description,Discovery and Integration(UDDI)

Sun Java System Application Server Platform Edition 8
    技术:
    JavaServer Pages Standard Tag Library(JSTL)封装了很多JSP程序的核心功能.
    JavaServer Faces
    是一种用来构建web程序的用户界面framework

学习J2EE第二天(XML基础)

今天学习了XML的一些基础知识和DTD用法

1.一个完整的xml实例文件:
slideSample.xml

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

<!--  A SAMPLE set of slides  -->

<!-- 用来引用自己的DTD -->
<!DOCTYPE slideshow SYSTEM "slideshow3.dtd" [
  <!-- 定义ENTITY,方便更换数据 -->
  <!ENTITY product  "WonderWidget">
  <!ENTITY products "WonderWidgets">  
 
  <!-- 定义外部文件的ENTITY-->
  <!ENTITY copyright SYSTEM "copyright.xml">
]>

<!-- SUBSTITUTIONS WORK IN ATTRIBUTES, TOO -->
<slideshow
    title="&product; Slide Show"
    date="Date of publication"
    author="Yours Truly"
    >

    <!-- PROCESSING INSTRUCTION -->
    <?my.presentation.Program QUERY="exec, tech, all"?>

    <!-- TITLE SLIDE -->
    <slide type="all">
       <slide-title>Wake up to &products;!</slide-title>
    </slide>

    <!-- TITLE SLIDE -->
    <slide type="all">
       <item>&copyright;</item>
    </slide>

    <!-- OVERVIEW -->
    <slide type="all">
      <slide-title>Overview</slide-title>
      <item>Why <em>&products;</em> are great</item>
      <item/>
      <item>Who <em>buys</em> &products;</item>
    </slide>

    <slide type="exec">
      <slide-title>Financial Forecast</slide-title>
      <item>Market Size &lt; predicted!</item>
      <item>Anticipated Penetration</item>
      <item>Expected Revenues</item>
      <item>Profit Margin </item>
    </slide>

    <slide type="tech">
      <slide-title>How it Works</slide-title>
      <item>First we fozzle the frobmorten</item>
      <item>Then we framboze the staten</item>
      <item>Finally, we frenzle the fuznaten</item>
      <item><![CDATA[Diagram:
                        
           frobmorten <------------ fuznaten
               |            <3>        ^
               | <1>                   |   <1> = fozzle
               V                       |   <2> = framboze   
             staten--------------------+   <3> = frenzle
                            <2>
      ]]></item>
    </slide>
</slideshow>

2.这是DTD文件:
slideSample.dtd

<?xml version='1.0' encoding='us-ascii'?>

<!--
    DTD for a simple "slide show".
-->

<!-- 定义元素 -->
<!ELEMENT slideshow (slide+)>

<!-- 定义元素属性 -->
<!ATTLIST slideshow
            title    CDATA    #REQUIRED
            date     CDATA    #IMPLIED
            author   CDATA    "unknown"
>
<!ELEMENT slide (image?, slide-title?, item*)>
<!ATTLIST slide
            type   (tech | exec | all) #IMPLIED
>

<!-- Defines the %inline; declaration -->
<!-- 定义一个外部DTD文件实体 -->
<!ENTITY % xhtml SYSTEM "xhtml.dtd">
%xhtml;

<!ELEMENT slide-title (%inline;)*>
<!ELEMENT item (%inline; | item)* >
<!ELEMENT image EMPTY>
<!ATTLIST image
            alt    CDATA    #IMPLIED
            src    CDATA    #REQUIRED
            type   CDATA    "image/gif"
>

3.创建Document Type Definition(DTD)

元素
?    可选(0或1)
*    0或多
+    1或多

属性
#REQUIRED    必须要求写
#IMPLIED    可以不写,如果不写程序会自动给它默认值
#FIXED "fixedValue"    必须和fixedValue一样
学习J2EE第三天(Cloudscape数据库的安装和了解)

IBM Cloudscape Version 10.1

简介

Cloudscape 是一个以 Java 类库形式提供的、轻量级的、可嵌入的关系引擎。它的本机接口是带有 Java 关系扩展的 Java Database Connectivity(JDBC)。它实现了 SQL92E 标准和许多 SQL 99 扩展。该引擎提供了事务和崩溃恢复,支持多个连接,而且支持使用一个连接的多个线程。因为 Cloudscape 是一个 Java 类库,您可以很容易地将它嵌入到任何 Java 应用程序或服务器架构中,同时还不会损害该应用程序的 Java 特性。当需要扩充数据库时,Cloudscape 支持复杂 SQL 事务和 JDBC,该特性允许它将应用程序迁移到其他 SQL 数据库,例如 IBM DB2® Universal Database™(UDB)。

Cloudscape Version 10:技术概述
http://www-128.ibm.com/developerworks/cn/db2/library/techarticles/dm-0408anderson/index.html
下载安装程序
http://www-128.ibm.com/developerworks/cn/db2/library/techarticles/dm-0408cline/index.html

一、安装数据库程序
设置环境变量DERBY_INSTALL=D:/Program Files/IBM/Cloudscape_10.1
设置CLASSPATH=%DERBY_INSTALL%/lib/derby.jar;%DERBY_INSTALL%/lib/derbytools.jar;

打开cmd.

//查看系统信息
>java org.apache.derby.tools.sysinfo   

二、数据库的简单使用
//进入了默认自带已经建立好的演示数据库文件夹
>cd D:/Program Files/IBM/Cloudscape_10.1/demo/databases/

启动ij工具.
>java org.apache.derby.tools.ij

ij>

//连接到数据库
ij> connect 'jdbc:derby:toursDB';

//建立一个叫address的表
ij> create table address (name varchar(60), street varchar(255), zipcode int);
0 rows inserted/updated/deleted

//建立一个叫zipmap的表
ij> create table zipmap (zipcode int, city varchar(255));
0 rows inserted/updated/deleted

//插入数据
ij> insert into zipmap values(201, 'shanghai');
1 row inserted/updated/deleted
ij> insert into zipmap values(123456, 'abcde');
1 row inserted/updated/deleted

//查看表里所有数据
ij> select * from zipmap;
ZIPCODE    |CITY
------------------------------------------------------------
201        |shanghai

123456     |abcde


2 rows selected

//查找数据
ij> select zipmap.zipcode from zipmap where zipmap.city = 'shanghai';
ZIPCODE
-----------
201

1 row selected

//删除表
ij> drop table zipmap;
0 rows inserted/updated/deleted
ij> drop table address;
0 rows inserted/updated/deleted

//断开连接
ij> disconnect;
//退出ij工具
ij> exit;
D:/Program Files/IBM/Cloudscape_10.1/demo/databases>

三、可以使用的驱动:
org.apache.derby.jdbc.EmbeddedDriver
这个就是可以嵌入到环境中的,当数据库与程序运行在同一个JVM中.

org.apache.derby.jdbc.ClientDriver
这个是用于网络的,比如client/server之类的应用.

四、Cloudscape Technical resource center
http://www.ibm.com/developerworks/db2/zones/cloudscape/

The developerWorks editors have assembled a broad collection of technical resources in the Cloudscape zone.  The "zone" is a great place to find all the information you need to get started with IBM Cloudscape.

学习J2EE第四天(从网络程序开始) 

今天我用Sun的服务器运行了一个最简单的网络程序.非常有成就感,尽管一点技术含量都没有.
但是我对未来充满了信心.
一、运行J2EE tutorial例子前必须做的准备工作:
1.修改build.properties
先找到这个文件,是<INSTALL>/j2eetutorial14/examples/common/build.properties
(1)设置j2ee.home

在Win下:
j2ee.home = C://Sun//AppServer

j2ee.home=C:/Sun/AppServer

(2)设置j2ee.tutorial.home property asant deployment and undeployment.
设置j2ee.tutorial.home.
在Unix下:
  j2ee.tutorial.home=/home/username/j2eetutorial14
Windows下:
  j2ee.tutorial.home=C:/j2eetutorial14

(3)You should not install the tutorial to a location with spaces in the path.

(4) If you did not use the default value (admin) for the admin user, set the admin.user property to the value you specified when you installed the Application Server.
(5) If you did not use port 8080, set the domain.resources.port property to the value specified when you installed the Application Server.
(6) Set the admin user's password in <INSTALL>/j2eetutorial14/examples/common/admin-password.txt to the value you specified when you installed the Application Server. The format of this file is AS_ADMIN_PASSWORD=password. For example:

  AS_ADMIN_PASSWORD=mypassword

二、几个概念:
在J2EE架构中,web组件和静态文件比如图片等被称为web resources.
web module是最小的可扩展的web resources单元.

To deploy a WAR on the Application Server, the file must also contain a runtime deployment descriptor.
The Application Server web application runtime DD is named sun-web.xml and is located in /WEB-INF/ along with the web application DD.

三、Web Modules
1.Packaging Web Modules
打包

asant build    //根据需要编译程序.
asant create-war//打包,产生的文件以war为后缀

2.Deploying Web Modules
4种方法:
Deploying with deploytool
Deploying with the Admin Console
Deploying with asadmin
    asadmin deploy full-path-to-war-file
Deploying with asant
    asant deploy-war

3.Updating Web Modules
先运行asant build,然后用deploytool或Admin Console下update

4.Undeploying Web Modules
4种方法:
deploytool
    # Select localhost:4848 from the Servers list.
    # Select the web module in the Deployed Objects list of the General tab.
    # Click the Undeploy button.
Admin Console
asadmin
    asadmin undeploy context_root
asant
    asant undeploy-war

学习J2EE第5天(Simple API for XML)

今天我学习了SAX的一些基础知识.
在网上看到了sun技术社区的一篇文章《使用JAXP处理XML文件》
这篇文章网址是
http://gceclub.sun.com.cn/yuanchuang/week-9/jaxp.html
我觉得他的算法太麻烦,自己想了一个简单点的,例子里的xml文件是向作者借来的,thx.

一、xml文件以及源代码
Test.xml
<?xml version="1.0" ?>
<customers>
  <customer>
    <id>#001</id>
    <name>Micke</name>
    <address>Najing</address>
  </customer>
  <customer>
    <id>#002</id>
    <name>Car</name>
    <address>Suzhou</address>
  </customer>
  <customer>
    <id>#003</id>
    <name>Jimmy</name>
    <address>ChengDu</address>
  </customer>
  <customer>
    <id>#004</id>
    <name>Henry</name>
    <address>Xi'an</address>
  </customer>
</customers>




Customers.java
/*
 * Created on 2005-12-9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
import java.util.*;
/**
 * @author Rey
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Customers {
    private ArrayList customers;
    public Customers() {
        customers = new ArrayList();
    }
    public void addCustomers(Customer c) {
        customers.add(c);
    }
    public String toString() {
        String newline = System.getProperty("line.separator");
        StringBuffer buf = new StringBuffer();

        for (int i = 0; i < customers.size(); i++) {
          buf.append(customers.get(i)).append(newline);
        }
        return buf.toString(); 
    }
}
class Customer {
      private String id;
      private String name;
      private String address;
     
      Customer(String id, String name, String address) {
          this.id = id;
          this.name = name;
          this.address = address;
      }

      public String getAddress() {
        return address;
      }

      public String getId() {
        return id;
      }

      public String getName() {
        return name;
      }

      public void setAddress(String string) {
        address = string;
      }

      public void setId(String string) {
        id = string;
      }

      public void setName(String string) {
        name = string;
      }
       
      public String toString(){
        return "Customer: ID='" + id + "' Name='" + name +
          "' Address='" + address + "'";
      }
}


Test.java
import java.io.*;

import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

import java.util.*;
/**
 * @author Rey
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Test extends DefaultHandler {
    private static ArrayList al;
    private StringBuffer textBuffer;
    public Test() {
        al = new ArrayList();
    }
    public static void main(String[] argv) {
        DefaultHandler handler = new Test();

        SAXParserFactory factory = SAXParserFactory.newInstance();

        try {
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse(new File("Test.xml"), handler);
        } catch (Throwable t) {
            t.printStackTrace();
        }
       ((Test)handler).showList();
        System.exit(0);
    }
    public void endElement(String namespaceURI, String sName, // simple name
            String qName // qualified name
        ) throws SAXException {
        if (qName.equals("id")||qName.equals("name")||qName.equals("address"))
            al.add(echoText());
    }

    public void characters(char[] buf, int offset, int len)
        throws SAXException {
        String s = new String(buf, offset, len);

        if (textBuffer == null) {
            textBuffer = new StringBuffer(s);
        } else {
            textBuffer.append(s);
        }
    }
    private String echoText(){
        String s = ""  +textBuffer;
        textBuffer = null;
        return s.trim();
    }
    public void showList() {
        Customers c = new Customers();
        String[] temp = (String[])al.toArray(new String[1]);
        for (int i = 0, j = 0; i < al.size()/3; i++) {
            c.addCustomers(new Customer(temp[j++], temp[j++], temp[j++]));
        }
        System.out.println(c);
    }
}


二、
程序输出:
Customer: ID='#001' Name='Micke' Address='Najing'
Customer: ID='#002' Name='Car' Address='Suzhou'
Customer: ID='#003' Name='Jimmy' Address='ChengDu'
Customer: ID='#004' Name='Henry' Address='Xi'an'

三、笔记
在阅读sun公司的文档时,有几个名词好半天都不知道什么意思,查了半天才知道.
关于XML的名称空间,限定名称、前缀和本地部分
名称空间中的元素和属性的名称中以冒号隔开
rdf:description
xlink:type
xsl:template
冒号前的部分叫前缀(prefix)
冒号后的部分叫本地部分(local part)
包括冒号在内的整个部分叫限定名称(qualified name)qName

http://gceclub.sun.com.cn/yuanchuang/week-9/jaxp.html
这篇文章的
Unmarshaller.java有错

//下面是改好的
//就是startElement和endElement方法中的
//sName.equals()都改为qName.equals()

import java.util.*;

import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
/**
* Test
* Create on 2004-4-10 19:20:27
* by Jiabo
*/
public class Unmarshaller extends DefaultHandler {
private Customers customers;
private Stack stack;
private boolean isStackReadyForText;
private Locator locator;

/**
* init
*/
public Unmarshaller() {
stack = new Stack();
isStackReadyForText = false;
}
/**
* @return customers
*/
public Customers getCustomers() {
return customers;
}
/**
* callbacks
*/
public void setDocumentLocator(Locator rhs) {
locator = rhs;
}

//==========================================
// SAX DocumentHandler methods
//==========================================

public void startElement(
String uri,
String sName,
String qName,
Attributes attrs) {
isStackReadyForText = false;

if (qName.equals("customers")) {
stack.push(new Customers());
} else if (qName.equals("customer")) {
stack.push(new Customer());
} else if (
qName.equals("id")
|| qName.equals("name")
|| qName.equals("address")) {
stack.push(new StringBuffer());
isStackReadyForText = true;
} else {
}
}

public void endElement(String namespaceURI, String sName, String qName){
isStackReadyForText = false;
Object temp = stack.pop();

if (qName.equals("customers")) {
customers = (Customers) temp;
} else if (qName.equals("customer")) {
((Customers) stack.peek()).addCustomer((Customer) temp);
} else if (qName.equals("id")) {
((Customer) stack.peek()).setId(temp.toString());
} else if (qName.equals("name")) {
((Customer) stack.peek()).setName(temp.toString());
} else if (qName.equals("address")) {
((Customer) stack.peek()).setAddress(temp.toString());
}
}

public void characters(char[] data, int start, int length) {
if (isStackReadyForText == true) {
((StringBuffer) stack.peek()).append(data, start, length);
} else {
}
}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值