读书人

J2EE6札记-(1)架构

发布时间: 2013-02-24 17:58:56 作者: rapoo

J2EE6笔记-(1)架构

感谢Sun公司的一系列解决方案,EJB3架构起来比SSH简单许多,而且EJB3天生有着强大的分布式部署特性,我个人认为EJB3要比SSH更有吸引力.

很多朋友认为EJB的架构很重量级,我个人认为那只是EJB2的时代,EJB3一样能构建一个很轻量便捷的系统.

首先我们来构建一个最基本的EJB3系统:


系统环境:

1.glassfish3.1

2.eclipse 3.7

3.Derby

不要问我为什么用这些不主流的东西,原因是他们很简单,拿来就能用.特别是derby,很方便的说.


1.glassfish3.1配置,不调优的话基本不用配置.不过一些常用命令还是要记录一下

控制台: http://localhost:4848/

创建域: asadmin create-domain f:

开始域: asadmin start-domain --domaindir f:

关闭域: asadmin stop-domain --domaindir f:

部署war: asadmin deploy f:j2ee.war

反部署: asadmin undeploy f:j2ee.war

运行DB: asadmin start-database --dbhome f:j2db

2.Derby

Derby有两种连接方式,(1)嵌入式,(2)客户端式,区别是嵌入式是独占连接

glassfish默认就有两个数据库连接,分别对应derby的两种连接方式,如果选择timepool,则当我们部署一个EJB的时候DB会同时启动,反之则要手动启动.

3.eclipse

(1)创建一个动态web项目

(2)在src/meta-inf文件夹中创建一个persistence.xml文件,内容如下


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"><h:head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Ajax</title></h:head><h:body><h:form id="form1" prependId="false"><h:outputScript name="jsf.js" library="javax.faces" target="head" /><h:outputText id="out1" value="#{count.count}" /><br /><!-- Increment the counter on the server, and the client --><h:commandButton id="button1" value="Count" onclick="jsf.ajax.request(this, event, {execute: this.id, render: 'testId'}); return false;" actionListener="#{count.increCount(234)}" /><br /><!-- Resets the counter --><h:commandButton id="reset" value="reset" onclick="jsf.ajax.request(this, event, {execute:'reset', render: 'out1'}); return false;" actionListener="#{count.reset}" /><h:panelGrid id="testId"><div><h:outputText value="#{count.count}" /></div></h:panelGrid></h:form></h:body></html>

配置完成,是不是很简单?

到目前为止,LIB文件夹的第三方包的个数为0.

部署完成后输入http://localhost:8080/J2EE/index.jsf就可以看到结果了.


读书人网 >J2EE开发

热点推荐