javafever


          我無富貴命,所喜性天然。壁立三千字,家無半吊錢。蟬鳴深巷里,人語短屋前。收拾英雄氣,耕作兩分田。

          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,還會有相應的圖形化工具。使用圖形化工具來管理很方便,大大提高了開發(fā)效率。由于這個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<%

          10javax.naming.Context ctx = new javax.naming.InitialContext();
          11javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("java:/comp/env/jdbc/jtest"
          );
          12java.sql.Connection con =
           ds.getConnection();
          13java.sql.Statement stmt =
           con.createStatement();
          14java.sql.ResultSet rs = stmt.executeQuery("select count(*) as c from authors"
          );
          15if (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。

          posted on 2005-08-09 20:21 javaFever 閱讀(734) 評論(1)  編輯  收藏 所屬分類: Java

          評論

          # re: ExadelStudio2.5插件使用(二) 2005-12-26 20:05 王國沖

          ewrhgerhgerhgergher  回復  更多評論   

          主站蜘蛛池模板: 乌兰浩特市| 大新县| 斗六市| 大名县| 通榆县| 合山市| 盐池县| 临夏市| 秀山| 平凉市| 民县| 凉山| 嘉义市| 屏山县| 汉沽区| 德钦县| 建宁县| 阿合奇县| 潮州市| 泰来县| 太原市| 衡东县| 昌平区| 光山县| 昌吉市| 庐江县| 日照市| 凌云县| 遵义县| 堆龙德庆县| 宁夏| 淮滨县| 云阳县| 三江| 河曲县| 巨鹿县| 涞水县| 临夏市| 张家界市| 永定县| 徐汇区|