mashiguang

          小馬快跑

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            20 隨筆 :: 0 文章 :: 60 評論 :: 0 Trackbacks

          #


          調(diào)用ejb時(shí),如果客戶端和ejb不在同一個jvm,就要設(shè)置InitialContext,不同的應(yīng)用服務(wù)器InitialContext寫法也不同.
          Context.INITIAL_CONTEXT_FACTORY:指定到目錄服務(wù)的連接工廠
          Context.PROVIDER_URL:目錄服務(wù)提供者URL

          //jboss:
          Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"
          Context.URL_PKG_PREFIXES, "org.jboss.naming"
          Context.PROVIDER_URL, "localhost:1099"

          //weblogic:
          Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"
          Context.PROVIDER_URL, "t3://localhost:7001"

          //apusic(金蝶):
          Context.INITIAL_CONTEXT_FACTORY, "com.apusic.jndi.InitialContextFactory"
          Context.PROVIDER_URL, "rmi://localhost:6888"

          //WebSphere:
          Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
          Context.PROVIDER_URL, "iiop://localhost:900"


          //J2EE  SDK(J2EE  RI):
          Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory"
          Context.PROVIDER_URL, "iiop://127.0.0.1:1050"

          //SilverStream:
          Context.INITIAL_CONTEXT_FACTORY, "com.sssw.rt.jndi.AgInitCtxFactory"
          Context.PROVIDER_URL, "sssw://localhost:80"

          //OC4J:
          Context.INITIAL_CONTEXT_FACTORY, "com.evermind.server.rmi.RMIInitialContextFactory"
          Context.PROVIDER_URL, "ormi://127.0.0.1/"

          //WAS5:
          Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory"
          Context.PROVIDER_URL, "iiop://localhost:2809"

           

          常用JNDI服務(wù)提供者連接工廠:
          Filesystem:  Com.sun.jndi.fscontext.FSContextFactory或者com.sun.jndi.fscontext.RefFSContextFactory
          LDAPv3:    Com.sun.jndi.ldap.LdapCtxFactory
          NDS:     com.novell.naming.service.nds.NdsInitialContextFactory
          NIS:     com.sun.jndi.nis.NISCtxFactory
          RMI registry: com.sun.jndi.rmi.registry.RegistryContextFactory
          IBM LDAP服務(wù)提供者:   com.ibm.jndi.LDAPCtxFactory
          BEA 名字服務(wù)提供者:   weblogic.jndi.WLInitialContextFactory
          JBOSS名字服務(wù)提供者:  org.jnp.interfaces.NamingContextFactory

          posted @ 2008-07-14 16:35 mashiguang 閱讀(14802) | 評論 (2)編輯 收藏

          自JDK1.0開始就存在包裝器類,但是在JDK5.0之前,必須手工地插入打包和拆包的代碼.
          JDK5.0中就有了自動打包功能,但在5.0中自動打包時(shí)存在一些差異,剛才看《java核心技術(shù)第7版》時(shí)才發(fā)現(xiàn).

          代碼1:
          Integer a=1000;
          Integer b
          =1000;
          System.out.println(a
          ==b);//false
          代碼2:
          Integer a=100;
          Integer b
          =100;
          System.out.println(a
          ==b);//true
          代碼3:
          Integer a=new Integer(100);
          Integer b
          =new Integer(100);
          System.out.println(a
          ==b);//false

          第一段代碼不成立,而第二段代碼成立的原因是:自動打包
          自動打包規(guī)范要求boolean,byte,char≤127,介于-128→127之間的short和int被包裝到固定的對象中.
          打包和拆包是編譯器認(rèn)可的,而不是虛擬機(jī),編譯器在生成類的字節(jié)碼時(shí),插入必要的方法調(diào)用,虛擬機(jī)只是執(zhí)行這些字節(jié)碼。

          第三段代碼不用多說肯定不成立.

           

          posted @ 2007-12-13 17:03 mashiguang 閱讀(1470) | 評論 (6)編輯 收藏


          在應(yīng)用的web.xml中配置了InvokerServlet.

           <servlet>
            
          <servlet-name>InvokerServlet</servlet-name>
            
          <servlet-class>
             org.apache.catalina.servlets.InvokerServlet
            
          </servlet-class>
            
          <init-param>
             
          <param-name>debug</param-name>
             
          <param-value>0</param-value>
            
          </init-param>
            
          <load-on-startup>-1</load-on-startup>
           
          </servlet>
            
          <servlet-mapping>
              
          <servlet-name>action</servlet-name>
              
          <url-pattern>*.do</url-pattern>
            
          </servlet-mapping>


          在jboss4.0.5中使用沒有問題,但遷移到4.2時(shí),當(dāng)使用到InvokerServlet就會出異常,解決辦法:
          在D:\jboss-4.2.1.GA\server\all\deploy\jboss-web.deployer下context.xml文件中的context元素中添加屬性:privileged

          <Context cookies="true" crossContext="true" privileged="true">

          出現(xiàn)這個問題可能是tomcat5.5和tomcat6的差異,暫未查明,本文只供個人參考,不接受評論.

           

          posted @ 2007-11-28 10:46 mashiguang| 編輯 收藏

               摘要: 用一個簡單的ejb3.0示例記錄ant打ear包的過程 源碼下載 環(huán)境: apache-ant-1.6.5 jboss-4.2.1.GA jboss-annotations-ejb3.jar jboss-ejb3.jar jboss-ejb3x.jar 最后三個包在jboss里有. 1,建ejb3.0項(xiàng)目 session bean接口:HelloWorld pub...  閱讀全文
          posted @ 2007-11-24 00:44 mashiguang 閱讀(6640) | 評論 (1)編輯 收藏

          使用commons mail時(shí)需要的jar包:
          1,commons-email-1.1.jar
          2,mail.jar
          3,activation.jar
          (在web應(yīng)用里只需要commons-email包)

          發(fā)送簡單的文字郵件:

          SimpleEmail email = new SimpleEmail();

          email.setHostName(
          "smtp.sina.com");
          email.setAuthentication(
          "username""password");//在郵件服務(wù)商處注冊的用戶名和密碼
          email.addTo("mailTo@163.com");
          email.setFrom(
          "username@sina.com""alias");

          email.setCharset(
          "UTF-8");//gbk或gb2312,只要支持中文就行
          email.setSubject("title");
          email.setMsg(
          "content");
          email.send();

          發(fā)送帶附件的郵件:
          // Create the attachment
          EmailAttachment attachment = new EmailAttachment();
          attachment.setPath(
          "mypictures/john.jpg");
          attachment.setDisposition(EmailAttachment.ATTACHMENT);
          attachment.setDescription(
          "Picture of John");
          attachment.setName(
          "John");

          // Create the email message
          MultiPartEmail email = new MultiPartEmail();
          email.setHostName(
          "mail.myserver.com");
          email.setAuthentication(
          "username""password");
          email.addTo(
          "jdoe@somewhere.org""John Doe");
          email.setFrom(
          "me@apache.org""Me");
          email.setCharset(
          "UTF-8");
          email.setSubject(
          "The picture");
          email.setMsg(
          "Here is the picture you wanted");

          // add the attachment
          email.attach(attachment);

          // send the email
          email.send();

          創(chuàng)建多個EmailAttachment對象,并調(diào)用MultiPartEmail.attach();就可以發(fā)送多個附件.

          發(fā)送HTML格式的郵件:

          發(fā)送html格式的郵件和簡單郵件的區(qū)別就在創(chuàng)建HtmlEmail對象
          并用email.setHtmlMsg(String)或email.setMsg(String)把含有html標(biāo)簽的字符串賦給email對象.
          HtmlEmail對象還有一個setTextMsg(String)方法,這個方法參數(shù)里的html標(biāo)簽會被當(dāng)做普通字符處理,不會被解析成html元素.
          更詳細(xì)內(nèi)容可以看apache commons-email的用戶指南.

          posted @ 2007-11-01 16:51 mashiguang 閱讀(1532) | 評論 (4)編輯 收藏

          貼子轉(zhuǎn)自http://hi.baidu.com/bobylou,轉(zhuǎn)之前并沒有驗(yàn)證文章里的方法是不是有效,估計(jì)原作者把它放到blog之前應(yīng)該做過測試了吧。

          Struts本身有一套完善的防止重復(fù)提交表單Token(令牌)機(jī)制,但筆者目前的項(xiàng)目自寫的framework沒有用到Struts,故也得自寫防止用戶因?yàn)楹笸嘶蛘咚⑿聛碇貜?fù)提交表單內(nèi)容的Token機(jī)制。不難,容易實(shí)現(xiàn)。

          實(shí)現(xiàn)原理:一致性。jsp生成表單時(shí),在表單中插入一個隱藏<input>字段,該字段就是保存在頁面端的token字符串,同時(shí)把該字符串存入session中。等到用戶提交表單時(shí),會一并提交該隱藏的token字符串。在服務(wù)器端,查看下是否在session中含有與該token字符串相等的字符串。如果有,那么表明是第一次提交該表單,然后刪除存放于session端的token字符串,再做正常業(yè)務(wù)邏輯流程;如果沒有,那么表示該表單被重復(fù)提交,做非正常流程處理,可以警告提示也可以什么也不做。

          看代碼。

          首先是Token主類。類很簡單,而且主要方法都給doc注釋了

          /*
          * blog: 
          http://hi.baidu.com/bobylou
          * $Revision: 1.1 $
          * $Date: 2007/07/18 10:02:55 $
          * $Author: bobrow$
          */


          package com.paizuo.framework.util;

          import java.util.ArrayList;

          import javax.servlet.http.HttpSession;

          public class Token {

              
          private static final String TOKEN_LIST_NAME = "tokenList";

              
          public static final String TOKEN_STRING_NAME = "token";

              
          private static ArrayList getTokenList(HttpSession session) {
                 Object obj 
          = session.getAttribute(TOKEN_LIST_NAME);
                 
          if (obj != null{
                    
          return (ArrayList) obj;
                 }
           else {
                    ArrayList tokenList 
          = new ArrayList();
                    session.setAttribute(TOKEN_LIST_NAME, tokenList);
                    
          return tokenList;
                 }

              }


              
          private static void saveTokenString(String tokenStr, HttpSession session) {
                 ArrayList tokenList 
          = getTokenList(session);
                 tokenList.add(tokenStr);
                 session.setAttribute(TOKEN_LIST_NAME, tokenList);
              }

             
              
          private static String generateTokenString(){
                 
          return new Long(System.currentTimeMillis()).toString();
              }


              
          /**
               * Generate a token string, and save the string in session, then return the token string.
               * 
               * 
          @param HttpSession
               *            session
               * 
          @return a token string used for enforcing a single request for a particular transaction.
               
          */

              
          public static String getTokenString(HttpSession session) {
                 String tokenStr 
          = generateTokenString();
                 saveTokenString(tokenStr, session);
                 
          return tokenStr;
              }


              
          /**
               * check whether token string is valid. if session contains the token string, return true. 
               * otherwise, return false.
               * 
               * 
          @param String
               *            tokenStr
               * 
          @param HttpSession
               *            session
               * 
          @return true: session contains tokenStr; false: session is null or tokenStr is id not in session
               
          */

              
          public static boolean isTokenStringValid(String tokenStr, HttpSession session) {
                 
          boolean valid = false;
                 
          if(session != null){
                    ArrayList tokenList 
          = getTokenList(session);
                    
          if (tokenList.contains(tokenStr)) {
                       valid 
          = true;
                       tokenList.remove(tokenStr);
                    }

                 }

                 
          return valid;
              }

          }



          怎么使用?

          在jsp頁面端。

          首先import該類:

          <%@ page import="com.paizuo.framework.util.Token" %>

          表單包含隱藏的token字符串:

           

          <form>

          <input type="hidden" name="<%=Token.TOKEN_STRING_NAME %>" value="<%=Token.getTokenString(session) %>">

          </form>

           

          在Server端action中進(jìn)行檢驗(yàn)。

           

          if(Token.isTokenStringValid(request.getParameter(Token.TOKEN_STRING_NAME), request.getSession())){
          //進(jìn)行正常業(yè)務(wù)流程
          }

          else{
          //進(jìn)行防重復(fù)提交處理流程
          }

          完畢。

          posted @ 2007-08-21 11:45 mashiguang 閱讀(4132) | 評論 (6)編輯 收藏

          1.創(chuàng)建mysql用戶并授權(quán):GRANT

          語法:
          GRANT privileges (columns)
          ON what
          TO username IDENTIFIED BY "password"
          WITH GRANT OPTION

          privileges :授予用戶的權(quán)限
          columns :權(quán)限運(yùn)用的列,可選
          what :權(quán)限運(yùn)用的對象,可以是數(shù)據(jù)庫,表,列
          username :權(quán)限授予的用戶
          password :密碼
          WITH GRANT OPTION子句是可選的。

          先來創(chuàng)建一個用戶plmm(漂亮mm),給她最大的權(quán)限,可以對所有的表做任何操作,密碼是"1234",但是她只能從本地登陸:
          grant all
          on *.*
          to plmm@localhost identified by "1234"
          再來創(chuàng)建一個用戶klmm(恐龍mm),我們只給她查看test數(shù)據(jù)庫里的table1表的權(quán)限,而且只能在192.168.0.%登陸,這里的"%"是個通配符,如果要使用通配符的話一定要用引號括起來.
          grant select
          on test.table1
          to klmm@'192.168.0.%' identified by "1234"

          下面表中列出privileges  除了上面用到的all和select還有哪些值可以選擇
          權(quán)限指定符 權(quán)限允許的操作
          ALTER 修改表和索引
          CREATE 創(chuàng)建數(shù)據(jù)庫和表
          DELETE 刪除表中已有的記錄
          DROP 拋棄(刪除)數(shù)據(jù)庫和表
          INDEX 創(chuàng)建或拋棄索引
          INSERT 向表中插入新行
          REFERENCE 未用
          SELECT 檢索表中的記錄
          UPDATE 修改現(xiàn)存表記錄
          FILE 讀或?qū)懛?wù)器上的文件
          PROCESS 查看服務(wù)器中執(zhí)行的線程信息或殺死線程
          RELOAD 重載授權(quán)表或清空日志、主機(jī)緩存或表緩存。
          SHUTDOWN 關(guān)閉服務(wù)器
          ALL 所有;ALL PRIVILEGES同義詞
          USAGE 特殊的“無權(quán)限”權(quán)限

          2.撤消用戶權(quán)限:revoke
          上面我們創(chuàng)建plmm用戶時(shí)給了她所有的權(quán)限,現(xiàn)在要撤消她更新(update)數(shù)據(jù)庫的權(quán)限
          revoke update ON *.* FROM plmm@localhost
          posted @ 2007-07-07 01:03 mashiguang 閱讀(355) | 評論 (0)編輯 收藏

                以往每添加一個servlet就要在web.xml里添加<servlet><servlet-mapping>,隨著項(xiàng)目的進(jìn)度,servlet數(shù)目越來越可觀.
          web.xml里也密密麻麻的排滿了<servlet><servlet-mapping>這些食之無味棄之崩潰的東西,有一種方法可以改善這種境況.
                在web.xml里添加如下的配置:
              <servlet>
                  
          <servlet-name>InvokerServlet</servlet-name>
                  
          <servlet-class>
                    org.apache.catalina.servlets.InvokerServlet
                  
          </servlet-class>
                  
          <init-param>
                      
          <param-name>debug</param-name>
                      
          <param-value>0</param-value>
                  
          </init-param>
                  
          <load-on-startup>-1</load-on-startup>
              
          </servlet>
              
              
          <servlet-mapping>
                  
          <servlet-name>InvokerServlet</servlet-name>
                  
          <url-pattern>/servlet/*</url-pattern>
              
          </servlet-mapping>
                ok,現(xiàn)在web.xml里保留這一個servlet配置就可以滿足所有的servlet調(diào)用了,比如調(diào)用UserManagerService這個servlet,在頁面表單里這樣寫:
          <form name="f" method="post" action="/servlet/com.mashiguang.servlet.UserManagerService">
                
          <input/>
                
          <submit/>
          </form>
                注意表單action "/servlet/"后面是這個servlet class的全名.
          posted @ 2007-07-06 19:17 mashiguang 閱讀(1983) | 評論 (5)編輯 收藏

          1.配置tomcat可以瀏覽web應(yīng)用目錄:
             修改%tomcat_home%/conf/web.xml,listings參數(shù)值為true代表可以瀏覽web應(yīng)用的目錄.

          <init-param>
             
          <param-name>listings</param-name>
             
          <param-value>true</param-value>
          </init-param>
          posted @ 2007-07-04 18:29 mashiguang 閱讀(366) | 評論 (0)編輯 收藏

          一.相關(guān)下載
             svn-1.4.0
             apache_2.0.55-win32-x86-no_ssl
             mod_auth_mysql-2.0.49-w32.zip
             site-1.0.4.zip(subclipse用于eclipse3.1.x)
             site-1.2.2.zip(subclipse用于eclipse3.2.x)
              
           如果apache和svn沒有自動集成成功,也可以手動修改apache httpd.conf文件如下3步:
            1.找到以下兩行:
             #LoadModule dav_module modules/mod_dav.so
             #LoadModule dav_fs_module modules/mod_dav_fs.so

             改為:
             LoadModule dav_module modules/mod_dav.so
             #LoadModule dav_fs_module modules/mod_dav_fs.so(網(wǎng)上很多說法是把這一行也去掉#注釋
          ,但好像并非必須去掉.)
            2.添加以下兩行:
             LoadModule dav_svn_module "C:/Program Files/Subversion/bin/mod_dav_svn.so"
             LoadModule authz_svn_module 
          "C:/Program Files/Subversion/bin/mod_authz_svn.so"
             # 
          "C:/Program Files/Subversion"是Subversion的安裝目錄
            3.在httpd.conf的最后添加如下內(nèi)容:
             <Location /svn>
                DAV svn
                SVNParentPath 
          "E:/svndemo"
                # SVNParentPath指向svn資源庫的上一級目錄
                # SVNPath 
          "E:/svndemo/repository"
                # SVNPath指向svn資源庫目錄
                # 使用SVNParentPath或SVNPath根據(jù)相應(yīng)需求
                # 關(guān)于如何創(chuàng)建svn資源庫目錄在本文最后有補(bǔ)充
             </Location>
            現(xiàn)在已經(jīng)可以通過http://localhost:8080/svn/repository/來訪問資源庫了.
          三.使用apache身份驗(yàn)證
           使用apache身份驗(yàn)證就要使用apache的htpasswd.exe命令生成密碼文件,示例如下:
            命令行下執(zhí)行:htpasswd –c E:\svndemo\svn_auth_passwd plmm
            參數(shù)-c創(chuàng)建密碼文件svn_auth_passwd并添加用戶plmm,然后會提示輸入密碼.
            繼續(xù)添加用戶:htpasswd -m E:\svndemo\svn_auth_passwd klmm
            參數(shù)-m在已有的密碼文件中添加新用戶klmm,并用MD5加密密碼.
            這樣就創(chuàng)建了一個密碼文件添加了兩個用戶.
           修改apache httpd.conf文件,添加如下內(nèi)容:
            <Location /svn>
               DAV svn
               SVNParentPath 
          "E:/svndemo"
              
               AuthType Basic
               AuthName 
          "Subversion repository"
               Require valid-user
               AuthUserFile 
          "E:/svndemo/svn_auth_passwd"
               # AuthUserFile指向密碼文件
            </Location>
           現(xiàn)在通過http://localhost:8080/svn/repository/訪問資源庫需要輸入用戶名密碼.
          四.結(jié)合mysql實(shí)現(xiàn)身份驗(yàn)證
           1.解壓上面下載的mod_auth_mysql-2.0.49-w32.zip文件,拷貝mod_auth_mysql.so文件至apache下modules目錄.
           2.修改apache httpd.conf文件,添加如下內(nèi)容:
             使apache加載mysql身份驗(yàn)證模塊:
              LoadModule mysql_auth_module modules/mod_auth_mysql.so
             配置apache用來驗(yàn)證用戶名密碼的數(shù)據(jù)庫表:
             <Location /svn>
                DAV svn
                SVNParentPath 
          "E:/svndemo"
              
                AuthType Basic
                AuthName 
          "Subversion repository"
                #AuthUserFile 
          "E:/svndemo/svn_auth_passwd"
                Require valid-user
            
                AuthMySQLHost localhost
                AuthMySQLUser root
                # AuthMySQLUser 數(shù)據(jù)庫登陸用戶名
                # AuthMySQLPassword 
          1234
                AuthMySQLDB svn
                # AuthMySQLDB 數(shù)據(jù)庫名
                AuthMySQLUserTable users
                # AuthMySQLUserTable 數(shù)據(jù)庫表名
                AuthMySQLNameField user_name
                # AuthMySQLNameField 用戶名字段
                AuthMySQLPasswordField user_passwd
                # AuthMySQLPasswordField 密碼字段
                # AuthMySQLMD5Passwords On
                AuthMySQLCryptedPasswords Off
             </Location>
           3.重啟apache,現(xiàn)在通過http://localhost:8080/svn/repository/訪問資源庫需要輸入mysql表中的用戶名密碼.
          五.相關(guān)命令
           安裝apache服務(wù):apache -k install
           卸載apache服務(wù):apache -k uninstall
           啟動apache服務(wù):apache -k start或net start Apache2
           停止apache服務(wù):apache -k stop 或net stop Apache2
           
           svn創(chuàng)建資源庫:svnadmin create E:\svndemo\repository
           啟動資源庫服務(wù):svnserve -d -r E:\svndemo\repository
           
           拷貝my.ini到c:\winnt
           安裝MySQL服務(wù):mysqld-nt -install
           啟動MySQL服務(wù):net start mysql
           停止MySQL服務(wù):net stop mysql
           卸載MySQL服務(wù):mysqld-nt -remove
           
          posted @ 2007-07-03 18:34 mashiguang 閱讀(2240) | 評論 (0)編輯 收藏

          僅列出標(biāo)題
          共2頁: 上一頁 1 2 
          主站蜘蛛池模板: 任丘市| 象州县| 东台市| 临夏县| 大埔县| 衢州市| 乳山市| 勐海县| 玉林市| 黄冈市| 林州市| 乌兰浩特市| 项城市| 驻马店市| 湖州市| 天峻县| 东安县| 同德县| 锦州市| 汉中市| 陈巴尔虎旗| 仁寿县| 怀来县| 汉川市| 邢台县| 海安县| 济宁市| 莱芜市| 桓台县| 吉安市| 鱼台县| 阳西县| 名山县| 吉首市| 农安县| 肃南| 兴安县| 东港市| 嘉峪关市| 北川| 安宁市|