日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
快速開(kāi)發(fā)EJB和J2EEWeb應(yīng)用

開(kāi)發(fā)J2EE Web應(yīng)用的準(zhǔn)備工作:

深澤ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場(chǎng)景,ssl證書(shū)未來(lái)市場(chǎng)廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書(shū)銷(xiāo)售渠道,可以享受市場(chǎng)價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書(shū)合作)期待與您的合作!

先安裝JSDK,再安裝JBoss.
安裝JSDK,必須獲得一套對(duì)應(yīng)于用戶的操作系統(tǒng)的JDK,
我的安裝的文件目錄是
Windows2000: d:\s1studio_jdk\j2sdk1.4.1
Linux: /root/s1studio_jdk/j2sdk1.4.1
為了用EJB, 需要一個(gè)j2ee-1.3.jar或者j2ee-1.2.jar,
如果安裝了Sun One Studio 或者 J2EE (www.sun.com )這個(gè)文件已經(jīng)有.
把這個(gè)文件放在classpath路徑上.
或者使用jboss-j2ee.jar, 安裝JBoss后在$JBoss\client中可找到.
建議安裝Sun One Studio, 用Sun One Studio編譯Java源程序,
不用設(shè)置classpath, 省去不少過(guò)程.

安裝JBoss:
把JBoss的壓縮包解開(kāi),放在任一目錄上,
我的安裝的文件目錄是
/dose/jboss-3.0.4_tomcat-4.1.12 (REDHAT8.0)
E:\jboss-3.0.4_tomcat-4.1.12 (WINDOWS2000)
WINDOWS2000, linux共用同一套JBoss.

配置JBoss:
啟動(dòng)JBoss需要執(zhí)行一個(gè)腳本文件:
linux:run.sh
WINDOWS對(duì)應(yīng)的是:run.bat

(1)
在JBoss\bin\run.bat (for Windows)開(kāi)頭插入一行
set JAVA_HOME = d:\s1studio_jdk\j2sdk1.4.1
在JBoss\bin\run.sh (for Linux)開(kāi)頭插入一行
JAVA_HOME="/root/s1studio_jdk/j2sdk1.4.1"

或者
(2)設(shè)置系統(tǒng)環(huán)境變量JAVA_HOME,指向JDK

運(yùn)行JBoss, run.sh或者run.bat
當(dāng)看到啟動(dòng)JBoss的信息時(shí),說(shuō)明啟動(dòng)了.
服務(wù)器簡(jiǎn)單的測(cè)試:
JBoss默認(rèn)的WEB端口為8080,我們可以在打開(kāi)一個(gè)瀏覽器輸入地址
http://localhost:8080/jmx-console
當(dāng)在瀏覽器看到JBoss的信息時(shí),說(shuō)明安裝配置JBoss成功了.

建立下面的目錄和文件(注意大小寫(xiě)).

FIRST.EAR
|
|-----META-INF (application.XML)
|
|-----First.jar
| |-----META-INF (ejb-jar.xml,jboss.xml)
| `-----Dev
| |-----First(FirstSession.java, FirstSessionHome.java, FirstSessionBean.java)
| |-----Delegate(NewDelegate.java)
| `-----Dao(MySQLDao.java)
|
`-----First.war(index.JSP)
|
`-----WEB-INF (jboss-web.xml, web.xml)
|-----classes
`-----lib

編譯JAVA源程序,生成class文件.
進(jìn)入JAVA源程序目錄, 運(yùn)行:
javac -classpath %classpath%;%jboss%\server\default\deploy\First.ear\First.jar *.java
或者
javac -classpath %jboss%\server\default\deploy\First.ear\First.jar;%jboss%\client\jboss-j2ee.jar *.java

Copy 目錄First.ear to jboss\server\default\deploy.
打開(kāi)瀏覽器輸入地址 http://localhost:8080/First

到此, 在瀏覽器看到: Hello! This My Session Bean From Jboss.
說(shuō)明這個(gè)EJB工作了.

如果按按鈕, 沒(méi)反應(yīng)或出錯(cuò). 原因沒(méi)安裝配置數(shù)據(jù)庫(kù), 下面安裝配置Postgres數(shù)據(jù)庫(kù)

For Windows2000
下載 PgSQL731wina1.exe (http://www.postgresql.org ),
Finally you will see the next line, you need enter the password for Administrator
最后你將看下一個(gè)行,你必須為用戶Administrator輸入password.
********************
Enter password of user `.\Administrator′:123456
********************

記下此password, 我的口令是123456.

從開(kāi)始菜單 > Programm > PostgresSQL > Adjust PostgresSQL Configuration file
它將在Wordpad中打開(kāi)PostgresSQL Configuration文件, 找到下列行,

#
# Connection Parameters
#
#tcpip_Socket = false
#ssl = false

#max_connections = 32
#superuser_reserved_connections = 2

#port = 5432

修改編輯:
#
# Connection Parameters
#
tcpip_socket = true
#ssl = false

#max_connections = 32
#superuser_reserved_connections = 2

port = 5432

接著,保存文件.

起動(dòng)PostgresSQL服務(wù)器:
開(kāi)始菜單>Programm>PostgresSQL>Utilies>Start PostgresSQL Server
起動(dòng)命令行:
開(kāi)始菜單>Programm>PostgresSQL>Utilies>Command Shell

執(zhí)行下列命令,準(zhǔn)備數(shù)據(jù),
Administrator@SAN /
$ dir

$ cd bin

$ createdb test

$ psql test

test=# create table users
test-# (name varchar(20),
test(# id varchar(20),
test(# country varchar(20));
test=# insert into users values (′Sam′, ′123′, ′China′);
test=# insert into users values (′Tom′, ′321′, ′USA′);
test=# insert into users values (′Sean′, ′231′, ′France′);

test=# select * from users;
name | id | country
------+-----+---------
Sam | 123 | China
Tom | 321 | USA
Sean | 231 | France
(3 rows)

test=#

到此, 數(shù)據(jù)準(zhǔn)備就緒.

For RedHat:
以root登陸, 執(zhí)行下列命令,準(zhǔn)備數(shù)據(jù),

mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data

Open and edit /usr/local/pgsql/data/pg_hba.conf

local all trust
host all 127.0.0.1 255.255.255.255 trust

just delete #, and save.

[root@localhost root]# su - postgres
-bash-2.05b$ /usr/bin/postmaster -i -D /usr/local/pgsql/data >logfile 2>&1 &
-bash-2.05b$ /usr/bin/createdb test
-bash-2.05b$ /usr/local/pgsql/bin/psql test
test=# .......the following same as Windows2000

到此, 數(shù)據(jù)準(zhǔn)備就緒.

執(zhí)行shutdown.bat or shutdown.sh, 停止Jboss Server.

找到JDBC drive.
為了在Jboss中使用連接池,需要拷貝jdbc drive 到Jboss/server/default/deploy , 在linux 我們能找到/usr/share/pgsql/pgjdbc2.jar,在wondows2000,我們能找到PostgreSQL\usr\share\postgresql\java\postgresql.jar
把其中之一復(fù)制到Jboss/server/default/deploy

配置Jboss

(1) 復(fù)制 $Jboss/examples/jca/postgres-service.xml 到 $Jboss/server/default/deploy/

(2) 打開(kāi)編輯Jboss/server/default/deploy/postgres-service.xml

PostgresDS

jdbc:postgresql://localhost/test
org.postgresql.Driver

Administrator
123456

在我的例子中,
windows2000, 用戶:Administrator,password:123456
Linux(RH8.0), 用戶:Postgres, 沒(méi)有password
因?yàn)镻ostgresSQL和windows2000使用不同的default用戶名,所以在linux和window2000中這文件不同.當(dāng)然,你可以加相同的PostgresSQL用戶名和password在linux和window2000中, 這樣這文件就相同了.

保存文件.

(3) 打開(kāi)編輯 $Jboss/server/default/conf/standardjbosscmp-jdbc.xml
找到:
java:/DefaultDS
Hypersonic SQL
加入:
java:/PostgresDS
Postgres
保存文件.

(4) open and edit $Jboss/server/default/conf/standardjaws.xml
找到:
java:/DefaultDS
Hypersonic SQL
false
加入:
java:/PostgresDS
Postgres
false
保存文件.

現(xiàn)在重啟JBoss.
打開(kāi)瀏覽器輸入地址http://localhost:8080/First br> 輸入ID,按按鈕

#p#

附件:源文件代碼

MysqlDao.java  

 
 
 
  1. package Dev.Dao;   
  2.  
  3. import java.sql.Connection;   
  4. import java.sql.SQLException;   
  5. import java.sql.Statement;   
  6. import java.sql.ResultSet;   
  7.  
  8. import javax.naming.InitialContext;   
  9. import javax.sql.DataSource;   
  10.  
  11.  
  12. public class MysqlDao {   
  13.  
  14.     public Connection getConnection() throws Exception {   
  15.  
  16.         InitialContext ctx = new InitialContext();   
  17.  
  18.         DataSource ds = (DataSource) ctx.lookup("java:/PostgresDS");   
  19.  
  20.  
  21.         Connection conn = null;   
  22.         Statement stmt = null;   
  23.  
  24.         try {   
  25.             conn = ds.getConnection();   
  26.  
  27.         } catch (SQLException sqlEx) {   
  28.             System.out.println("Error connect to pool.");   
  29.         }   
  30.  
  31.         return conn;   
  32.     }   
  33.  
  34.     public String getName(String id) throws Exception {   
  35.  
  36.         Connection conn = null;   
  37.         Statement stmt = null;   
  38.         ResultSet rs = null;   
  39.         String name = "";   
  40.  
  41.         try {   
  42.             conn = getConnection();   
  43.             if ( conn !=null )System.out.println("Get conecttion. "+ conn.toString());   
  44.             stmt = conn.createStatement();   
  45.             if ( stmt !=null )System.out.println("Get Statement. "+ stmt.toString());   
  46.             String sql = "SELECT * from users where id = '"+id+"'";   
  47.             System.out.println("Sql from getId(): "+sql);   
  48.            rs = stmt.executeQuery(sql);   
  49.             if ( rs !=null )System.out.println("Get result. ");   
  50.            if (rs.next()){   
  51.             name = rs.getString("name");   
  52.                }   
  53.  
  54.         } catch (Exception sqlEx) {   
  55.         System.out.println("Error from getName().");   
  56.                 System.out.println("Error from DAO.getName() :" + sqlEx.getMessage());   
  57.         }finally {   
  58.             if (conn != null) {   
  59.                try { conn.close(); } catch (Exception sqlEx) { }   
  60.             }   
  61.         }   
  62.         return name;   
  63.     }   
  64.  
  65.     public String getCountry(String id) throws Exception {   
  66.  
  67.         Connection conn = null;   
  68.         Statement stmt = null;   
  69.         String name = "";   
  70.  
  71.         try {   
  72.             conn = getConnection();   
  73.             stmt = conn.createStatement();   
  74.             String sql = "SELECT * from users where id = '"+id+"'";   
  75.             System.out.println("Sql from getCountry(): "+sql);   
  76.                java.sql.ResultSet rs = stmt.executeQuery(sql);   
  77.                if (rs.next())   
  78.             {   
  79.                    name = rs.getString("Country");   
  80.               }   
  81.  
  82.         } catch (SQLException sqlEx) {   
  83.             System.out.println("Error from getCountry().");   
  84.         }finally {   
  85.             if (conn != null) {   
  86.                try { conn.close(); } catch (Exception sqlEx) { }   
  87.             }   
  88.         }   
  89.         return name;   
  90.     }   
  91.  
  92. }   
 
 
 
  1. /*  
  2. **  
  3. **NewDelegate.java   
  4. **  
  5. */  
  6. package Dev.Delegate;   
  7.  
  8. import java.lang.*;   
  9. import Dev.First.*;   
  10.  
  11.  
  12. public class NewDelegate {   
  13.  
  14.     Dev.First.FirstSession bean = null;   
  15.        
  16.     public NewDelegate( ){   
  17.        try {   
  18.        javax.naming.InitialContext ctx = new javax.naming.InitialContext();   
  19.        Object objref = ctx.lookup("ejb/FirstSession");   
  20.        Dev.First.FirstSessionHome testBean = (Dev.First.FirstSessionHome)   
  21.           javax.rmi.PortableRemoteObject.narrow   
  22.           (objref,Dev.First.FirstSessionHome.class);   
  23.        bean = testBean.create();   
  24.        System.out.println("From JSP");   
  25.     } catch (Exception NamingException) {   
  26.            NamingException.printStackTrace();   
  27.     }   
  28.     }   
  29.      
  30.     public String Welcome() {   
  31.     String msg = "";   
  32.     try {   
  33.             msg = bean.Welcome();   
  34.     } catch (Exception NamingException) {    
  35.            NamingException.printStackTrace();   
  36.          }   
  37.            return msg;   
  38.     }   
  39.        
  40.     public String getName(String id) {   
  41.     String name = "";   
  42.     try {   
  43.             name = bean.getName(id);   
  44.     } catch (Exception NamingException) { NamingException.printStackTrace();}   
  45.         return name;   
  46.     }    
  47.        
  48.     public String getCountry(String id) {   
  49.     String country = "";   
  50.     try {   
  51.              country = bean.getCountry(id);   
  52.     } catch (Exception NamingException) { NamingException.printStackTrace();}   
  53.         return country;   
  54.     }           
  55. }   
   
 
 
  1. /*  
  2. **  
  3. **FirstSession.java   
  4. **  
  5. */ 
  6. package Dev.First;   
  7.  
  8. import java.lang.*;   
  9. import java.rmi.RemoteException;   
  10. import javax.ejb.CreateException;   
  11. import javax.ejb.EJBException;   
  12. import javax.ejb.SessionBean;   
  13. import javax.ejb.SessionContext;   
  14.  
  15.  
  16. public interface FirstSession extends javax.ejb.EJBObject{   
  17.  
  18.          public String Welcome() throws java.rmi.RemoteException;   
  19.             
  20.          public String getName(String id) throws java.rmi.RemoteException;   
  21.             
  22.          public String getCountry(String id) throws java.rmi.RemoteException;   
  23.  
  24. }   
   
 
 
  1. /*  
  2. **  
  3. **FirstSessionHome.java   
  4. **  
  5. */ 
  6. package Dev.First;   
  7.  
  8. import java.lang.*;   
  9. import java.rmi.RemoteException;   
  10. import javax.ejb.CreateException;   
  11. import javax.ejb.EJBException;   
  12. import javax.ejb.SessionBean;   
  13. import javax.ejb.SessionContext;   
  14.  
  15.  
  16. public interface FirstSessionHome extends javax.ejb.EJBHome{   
  17.  
  18. public FirstSession create() throws javax.ejb.CreateException, java.rmi.RemoteException;   
  19.  
  20. }   
   
 
 
  1. /*  
  2. **  
  3. **FirstSessionBean.java   
  4. **  
  5. */ 
  6. package Dev.First;   
  7.  
  8. import java.rmi.RemoteException;   
  9. import javax.ejb.CreateException;   
  10. import javax.ejb.EJBException;   
  11. import javax.ejb.SessionBean;   
  12. import javax.ejb.SessionContext;   
  13.  
  14.  
  15. public class FirstSessionBean implements SessionBean{   
  16.  
  17. public void ejbCreate() throws CreateException {   
  18.  
  19. }   
  20.  
  21. public String Welcome(){   
  22.       String msg="Hello! This My Session Bean From Jboss.";   
  23.       System.out.println(msg);   
  24.       return msg;   
  25. }   
  26.  
  27. public String getName(String id){   
  28.       String name = "";   
  29.       System.out.println("From bean before getName :"+ name);   
  30.       try{   
  31.       Dev.Dao.MysqlDao dao = new Dev.Dao.MysqlDao();   
  32.       name = dao.getName(id);   
  33.       System.out.println("From bean after getName :"+ name);   
  34.       }catch(Exception e){ System.out.println(e.getMessage());}   
  35.       return name;   
  36. }   
  37.  
  38. public String getCountry(String id){   
  39.       String country = "";   
  40.       try{         
  41.       Dev.Dao.MysqlDao dao = new Dev.Dao.MysqlDao();   
  42.       country = dao.getCountry(id);   
  43.       }catch(Exception e){ }         
  44.       return country;   
  45. }   
  46.  
  47. public void setSessionContext( SessionContext aContext ) throws EJBException {   
  48.  
  49. }   
  50.  
  51. public void ejbActivate() throws EJBException {   
  52.  
  53. }   
  54.  
  55. public void ejbPassivate() throws EJBException {   
  56.  
  57. }   
  58.  
  59. public void ejbRemove() throws EJBException {   
  60.  
  61. }   
  62.  
  63. }   
   
 
 
  1. /*不要將下面這行放入index.jsp  
  2. **  
  3. **index.jsp   
  4. **  
  5. */不要將上面這行放入index.jsp  
  6. < %@page language="java" %>   
  7.  
  8. < %   
  9.  
  10.     String msg = "";   
  11.     String msg1 = "";   
  12.     Dev.Delegate.NewDelegate nn = new Dev.Delegate.NewDelegate();   
  13.     if (request.getParameter("id") != null &&    
  14.            request.getParameter("id") != ""&&    
  15.            !request.getParameter("id").equals("")){   
  16.         String id = request.getParameter("id");   
  17.         String name = "";   
  18.         Dev.Dao.MysqlDao dao = new Dev.Dao.MysqlDao();   
  19.         name = nn.getName(id);      //access database through session bean   
  20.         //name = dao.getName(id);   //access database directly   
  21.         if(name!= null && !name.equals("")){   
  22.             msg1 ="Welcome  " + name +" !     You are from  "+ dao.getCountry(id)+ " .";   
  23.         }else{   
  24.             msg1 ="Please Check Your ID. : " + id;   
  25.         }   
  26.  
  27.     }   
  28.     msg = nn.Welcome() ;   
  29. %>   
  30. < html>   
  31.  
  32. < head>   
  33. < title>Welcome< /title>   
  34. < /head>   
  35.  
  36. < body bgcolor="#FFFFCC">   
  37. < br> < %= msg %> < br>   
  38.  
  39. < FORM ACTION="index.jsp" method="post">   
  40.  
  41. < P>Your ID:   
  42. < INPUT TYPE="TEXT" NAME="id" size = "10">< /P>   
  43.  
  44.  
  45. < P>< INPUT TYPE="SUBMIT" NAME="SUBMIT">< /P>   
  46. < /FORM>   
  47. < br>   
  48. < br>   
  49.  
  50. < %=(msg1 == "")? "":msg1 + "< br> < br> < br>Connect to Database OK." %>   
  51.  
  52. < /body>   
  53. < /html> 
   
 
 
  1. < !--不要將此以下5行存入文件  
  2. **  
  3. **ejb-jar.xml  
  4. **  
  5. -->不要將此以上5行存入文件, 下同.  
  6. < ?xml version="1.0" encoding="UTF-8"?>   
  7. < !DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"    
  8. "http://java.sun.com/dtd/ejb-jar_2_0.dtd">   
  9.  
  10. < ejb-jar>   
  11.  
  12.  < description>First< /description>   
  13.  < display-name>First< /display-name>   
  14.  
  15. < enterprise-beans>   
  16.  
  17. < !-- Session Beans -->   
  18. < session id="MyFirstSession">   
  19.      < display-name>My First Session Bean< /display-name>   
  20.      < ejb-name>FirstSession< /ejb-name>   
  21.      < home>Dev.First.FirstSessionHome< /home>   
  22.      < remote>Dev.First.FirstSession< /remote>   
  23.      < ejb-class>Dev.First.FirstSessionBean< /ejb-class>   
  24.      < session-type>Stateless< /session-type>   
  25.      < transaction-type>Container< /transaction-type>   
  26. < /session>   
  27. < /enterprise-beans>   
  28. < assembly-descriptor>   
  29. < /assembly-descriptor>   
  30. < /ejb-jar>   

jboss.xml

   
 
 
  1. < ?xml version="1.0" encoding="UTF-8"?>   
  2. < !DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS//EN" "http://www.jboss.org/j2ee/dtd/jboss.dtd">   
  3.  
  4. < jboss>   
  5.  
  6. < enterprise-beans>   
  7.  
  8. < session>   
  9. < ejb-name>FirstSession< /ejb-name>   
  10. < jndi-name>ejbFirstSession< /jndi-name>   
  11. < /session>   
  12.  
  13. < /enterprise-beans>   
  14.  
  15. < resource-managers>   
  16. < /resource-managers>   
  17.  
  18. < /jboss>   

jboss-web.xml

   
 
 
  1. < ?xml version="1.0" encoding="UTF-8"?>   
  2. < !DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 2.2//EN"    
  3. "http://www.jboss.org/j2ee/dtd/jboss-web.dtd">   
  4.  
  5. < jboss-web>   
  6.  
  7.  
  8.     < resource-ref>   
  9.         < res-ref-name>jdbcPostgresDS< /res-ref-name>   
  10.         < res-type>javax.sql.DataSource< /res-type>   
  11.         < jndi-name>java:/PostgresDS< /jndi-name>   
  12.     < /resource-ref>   
  13.  
  14. < /jboss-web>  

web.xml

   
 
 
  1. < ?xml version="1.0" encoding="ISO-8859-1"?>   
  2.  
  3. < !DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"   
  4. "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">   
  5.  
  6. < web-app>   
  7.  
  8. < resource-ref>   
  9.   < description>Postgresql driver< /description>   
  10.   < res-ref-name>jdbcPostgresDS< /res-ref-name>   
  11.   < res-type>javax.sql.DataSource< /res-type>   
  12.   < res-auth>Container< /res-auth>   
  13. < /resource-ref>   
  14.  
  15. < /web-app>  

application.xml

   
 
 
  1. < ?xml version="1.0" encoding="ISO-8859-1"?>   
  2.  
  3. < application>   
  4. < display-name>First< /display-name>   
  5. < module>   
  6. < web>   
  7. < web-uri>First.war< /web-uri>    新聞名稱:快速開(kāi)發(fā)EJB和J2EEWeb應(yīng)用
    當(dāng)前URL:http://www.dlmjj.cn/article/dhpideo.html