下面我们来完成对bean操作的jsp页面。这些面页代码都很易懂,我不再做详细的说明了,所有的页面的工作与文件名一样对数据库中的数据进行add、list、delete、edit操作(代码见附录)。我们需要将这些jsp文件存入hdsite\src\jsp目录中去。 同时为用户建立一个欢迎页面index.html(见附录),我们将这个html文件存入hdsite\src\web目录中。
这之后我们同样需要改动web.xml文件来将web容器的框架告诉给orion,如下:
<ejb-ref>
<ejb-ref-name>ejb/addressbook</ejb-ref-name>
<ejb-ref-type>entity</ejb-ref-type>
<home.net.chinacode.addressbook.addressbook</home>
<remote.net.chinacode.addressbook.addressentry</remote>
</ejb-ref>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
我们把这段加入到web.xml中的web-app段中去。同时将原来我们做的servlet-mapping中的url-pattern指如/hello这样的url。第一段是向web容器告知一个可以使用的entity bean的框架,以便jsp能够得知ejb的结构。第二段则是设定默认的欢迎页面的文件名为index.html。这样服务器会先在目录下寻找这个文件来返回给客户。
还有最后一件事情,就是改动build.xml文件以方便ant来编译系统,如果你希望成为一名好的j2ee开发人员,我更建议你来改动这个文件,这里由于篇幅限制不列出全部,只列出需要改动的web段:
<target name="web-classes" depends="prepare">
<javac srcdir="${src.dir}"
destdir="${lib.dir}/web/web-inf/classes"
includes="java.net/chinacode/web/**"
classpath="${lib.dir}/ejb:${orion.dir}/ejb.jar:${orion.dir}/jndi.jar:${orion.dir}/orion.jar" />;
</target>
<target name="jsp" depends="prepare">
<copydir
web" > src="${src.dir}/jsp"> </target>
<target name="html" depends="prepare">
dest="${lib.dir}/web" />
</target>
<target name="web-war" depends="jsp,html,web-classes,web-web-inf">
<jar
web" jarfile="${rel.dir}/${name}-web.war"> </target>
更为详细的可以见附录。这之后,我们可以试着在hdsite目录下运行ant了。运行完ant后我们再重新启动一次orion,可以看到它的提示如下:
auto-unpacking c:\hdsite\rel\helloejb.ear... done.
auto-unpacking c:\hdsite\rel\helloejb\helloejb-web.war... done.
auto-deploying helloejb-ejb.jar (class 27.net.chinacode.hello.hello' had been updated)...
auto-creating table: create table.net_chinacode_addressbook_addressentry (name varchar(255) not null primary key, address varchar(255) null, city varchar(255) null)
done.
orion/1.3.8 initialized
真是太神奇了,orion为我们所想建好了数据库(默认情况下它使用了内置的hypersonic数据库)。如果是在同一台机器上,哪么你试试http://localhost/helloejb/ 就可以看到一个简单的地址本工具了。再试试http://localhost/helloejb/hello 哪么访问的就是从前的session bean的例子了。
我们完成了在orion下的两个ejb例程的开发,希望大家能以此为起点进行j2ee的大家庭。
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 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器