ExadelStudio2.5插件使用(二)

ExadelStudio2.5插件使用(二)

{建立应用jtest}
建立一个名为jtest的Exadel JSF Project,模板选用JSFBlank。

{配置Tomcat数据源}
我使用的是Tomcat5.5.10,数据库是SQLServer2000_SP3(好象都是比较新的版本,难怪有人说我喜新厌旧)。
我的Web应用程序名叫jtest,所以我修改{TOMCAT_HOME}/conf/Catalina/localhost/jtest.xml文件,在里面增加数据源配置。文件内容如下:

< Context  docBase ="E:/java/jtest/WebContent"
  path
="/jtest"
  reloadable
="true" >
 
< Resource  name ="jdbc/jtest"
   type
="javax.sql.DataSource"
   password
="1"
   driverClassName
="com.microsoft.jdbc.sqlserver.SQLServerDriver"
   maxIdle
="2"
   maxWait
="5000"
   username
="sa"
   url
="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs"
   maxActive
="4" />
</ Context >

在包资源管理器中找到WebContent/WEB-INF/web.xml,打开,安装Exadel后会自动使用Exadel的XML编辑器打开XML文档,如果是web.xml和faces-config.xml,还会有相应的图形化工具。使用图形化工具来管理很方便,大大提高了开发效率。由于这个web.xml比较简单,所以我直接编写源文件,最终的文件内容如下:

<? xml version="1.0" ?>  
< web-app  version ="2.4"  
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" >  

    
< context-param >
        
< param-name > javax.faces.STATE_SAVING_METHOD </ param-name >
        
< param-value > server </ param-value >
    
</ context-param >

    
< context-param >
        
< param-name > javax.faces.CONFIG_FILES </ param-name >
        
< param-value > /WEB-INF/faces-config.xml </ param-value >
    
</ context-param >

    
< listener >
        
< listener-class > com.sun.faces.config.ConfigureListener </ listener-class >
    
</ listener >

    
<!--  Faces Servlet  -->
    
< servlet >
        
< servlet-name > Faces Servlet </ servlet-name >
        
< servlet-class > javax.faces.webapp.FacesServlet </ servlet-class >
        
< load-on-startup >  1  </ load-on-startup >
    
</ servlet >


    
<!--  Faces Servlet Mapping  -->
    
< servlet-mapping >
        
< servlet-name > Faces Servlet </ servlet-name >
        
< url-pattern > *.jsf </ url-pattern >
    
</ servlet-mapping >
    
    
< resource-ref >
     
< description > DataSource </ description >
     
< res-ref-name > jdbc/jtest </ res-ref-name >
     
< res-type > javax.sql.DataSource </ res-type >
     
< res-auth > Container </ res-auth >
    
</ resource-ref >
    
</ web-app >

除了<resource-ref>标签里定义数据源是我自己手动增加的内容以外,其它都是Exadel自动产生的,真是很方便。
在配置的过程中遇到点小麻烦:我的OS是Windows2003,JDBC是微软官方的,开始SQLServer2000没有打SP3,怎么也配不成功,结果一打SP3就行了,浪费了不少光阴。

{测试数据源}
最后,写一个index.jsp文件来测试数据源有没有工作,文件内容如下:

 1 <% @ page language = " java "   %>
 2 < html >
 3 < head >
 4 < title > jtest </ title >
 5 </ head >
 6 < body >
 7 < h2 > Result </ h2 >
 8
 9 <%
10 javax.naming.Context ctx  =   new  javax.naming.InitialContext();
11 javax.sql.DataSource ds  =  (javax.sql.DataSource) ctx.lookup( " java:/comp/env/jdbc/jtest " );
12 java.sql.Connection con  =  ds.getConnection();
13 java.sql.Statement stmt  =  con.createStatement();
14 java.sql.ResultSet rs  =  stmt.executeQuery( " select count(*) as c from authors " );
15 if  (rs.next())  out .println( " count is: "   +  rs.getInt( " c " ));
16 rs.close();
17 stmt.close();
18 con.close();
19 %>
20


将文件存放在/WebContent/目录下,然后运行/ant/build.xml,最后启动Tomcat,如果能看到结果,表示配置一切OK。

你可能感兴趣的:(ExadelStudio2.5插件使用(二))