隨筆-40  評(píng)論-66  文章-0  trackbacks-0
            2006年11月21日
          springside3背景struts2.1.2 spring2.5.6 Hibernate3.4GA


          1.struts2

          使用ZeroConfig + CodeBehind插件,實(shí)現(xiàn)約定大于配置的零配置文件風(fēng)格.

          根本不用配置struts.xml文件





          這里就是action實(shí)現(xiàn)annotation  CodeBehind。
          如方法


          通過 /user/user!input.action訪問, 并轉(zhuǎn)到 /user/user-xxx.jsp頁面
          即namespace + action name + "-" + "xxx.jsp"


           另外其中 action中需要注入的 service 使用annotation ,在set方法前 加入@request 或 @ autowired 或 @resource
          注釋(具體是用那個(gè)暫時(shí)無法搞清楚,總之我用request 就不行,另外兩個(gè)都可以)



          有了這個(gè)代碼之后 就能注入spring 環(huán)境中的 id = userManager 的bean (我個(gè)人理解)

          而spring中  id = userManager 的bean  也是通過自動(dòng)注入完成的

          主要代碼是 applicationContext.xml文件中的
          代碼:




          2.spring

          spring2.5.6的annotation特性用的比較泛濫。 新手剛開始看的一頭霧水很正常。

          xml文件中配置自動(dòng)注冊(cè)bean,通過掃描包中的帶注解的類。即這個(gè)代碼:




          掃描到下面的類,就自動(dòng)注冊(cè)成 id=userManager





          3.hibernate
          使用hiberante3 注解,不要XML配置,實(shí)體類注解不用多說。

          需要注意的是entity類的掃描配置




          看清楚是掃描包,不是掃描類! 所以實(shí)體類com.mylu.User是無法掃描到,要放在 com.mylu.xxx.User才能掃描到!




          下邊按照ss3風(fēng)格做的例子,去掉spring security 框架的, 結(jié)構(gòu)更清晰。

          下載:實(shí)例代碼


          附:
          類庫
          posted @ 2009-01-08 17:01 Super·shen BLOG 閱讀(1796) | 評(píng)論 (2)編輯 收藏

          在jsp中,其實(shí)jsp就是servlet,jsp和servlet也都是一個(gè)class:

          1 .request.getRealPath(),這個(gè)方法已經(jīng)不推薦使用,在servlet后繼版本中將被取締。

          2.getServletContext().getRealPath("/")這個(gè)方法比較好用,可以直接在servlet和jsp中使用。

          3.request.getSession().getServletContext().getRealPath()也可以在jsp和servlet使用。

          4.this.getClass().getClassLoader().getResource("").getPath(),這個(gè)方法可以在任意jsp,servlet,java文件中使用,因?yàn)椴还苁莏sp,servlet其實(shí)都是java程序,都是一個(gè)class。所以它應(yīng)該是一個(gè)通用的方法。

          posted @ 2008-09-17 14:55 Super·shen BLOG 閱讀(504) | 評(píng)論 (0)編輯 收藏

          普遍的,簡單的權(quán)限系統(tǒng)要求:

          1.系統(tǒng)所有資源定義 [資源表]   ( 還可以分為更小的權(quán)限表,操作表,這里通叫資源表)
          2.定義角色 [角色表]
          3.給角色指定資源(一個(gè)角色可以管理多個(gè)資源) [角色-資源表]
          4.定義用戶組 [用戶表]
          5.給用戶組指定角色(一個(gè)用戶組可以擁有多種角色) [用戶組-角色表]
          6.給用戶指定角色(一個(gè)用戶可以擁有多種角色,可以直接指定角色,也可以繼承用戶組的角色)[用戶-角色表]

           


          查找權(quán)限時(shí):

          根據(jù)用戶ID[用戶-角色表]或用戶組ID[用戶組-角色表],查到所有角色I(xiàn)D,再[角色-資源表]找到所有角色下的所有資源。

          此就是用戶擁有的資源。(資源一般為模塊,當(dāng)然也可以分更細(xì)的定義為頁面,操作方法等)


          此權(quán)限設(shè)計(jì)適合于模塊化訪問系統(tǒng),如OA


          當(dāng)然很多系統(tǒng)因地而已,不可能完全滿足,按照自己系統(tǒng)需求設(shè)計(jì)是最合適的設(shè)計(jì)。



          posted @ 2008-08-18 16:17 Super·shen BLOG 閱讀(804) | 評(píng)論 (0)編輯 收藏
          提交頁面

          插入

          用戶:
          密碼:
          處理頁面add2.cgi 代碼 #include #include #include #include "sqlite3.h" #include "cgic.h" int cgiMain() { printf("Content-type:text/html\n\n"); printf(""); sqlite3 *db=NULL; char *zErrMsg = 0; int rc; rc = sqlite3_open("test.db", &db); if(rc){ printf("Can't open database\n"); //這里改了。要是按原先的,會(huì)提示stderr未定義,我不知道為什么。哪位朋友知道一定要告訴我哦。 sqlite3_close(db); exit(1); } else printf("open test.db successfully!\n"); char username[241]; cgiFormString("username", username, 241); fprintf(cgiOut, "username:
          \n");
          cgiHtmlEscape(username);
          fprintf(cgiOut, "
          \n"); char password[241]; cgiFormString("password", password, 241); fprintf(cgiOut, "password:
          \n");
          cgiHtmlEscape(password);
          fprintf(cgiOut, "
          \n"); char sql[300]={'\0'}; //不能用指針! //插入數(shù)據(jù) sprintf(sql, "INSERT INTO \"user\" VALUES('%s', '%s');", username,password); //sql = "INSERT INTO \"user\" VALUES('username', 'password');" ; sqlite3_exec( db , sql , 0 , 0 , &zErrMsg ); printf(sql); printf("插入數(shù)據(jù)成功!\n"); int nrow = 0, ncolumn = 0; char **azResult; //二維數(shù)組存放結(jié)果 //查詢數(shù)據(jù) /* int sqlite3_get_table(sqlite3*, const char *sql,char***result , int *nrow , int *ncolumn ,char **errmsg ); result中是以數(shù)組的形式存放你所查詢的數(shù)據(jù),首先是表名,再是數(shù)據(jù)。 nrow ,ncolumn分別為查詢語句返回的結(jié)果集的行數(shù),列數(shù),沒有查到結(jié)果時(shí)返回0 */ char *sql2 = "SELECT * FROM user"; sqlite3_get_table( db , sql2 , &azResult , &nrow , &ncolumn , &zErrMsg ); int i = 0 ; printf( "row:%d column=%d
          " , nrow , ncolumn ); printf( "\nThe result of querying is : \n" ); for( i=0 ; i<( nrow + 1 ) * ncolumn ; i++ ) printf( "azResult[%d] = %s
          ", i , azResult[i] ); //釋放掉 azResult 的內(nèi)存空間 sqlite3_free_table( azResult ); sqlite3_close(db); //關(guān)閉數(shù)據(jù)庫 return 0; } 請(qǐng)注意數(shù)據(jù)庫文件 test.db的訪問權(quán)限! 這里改成777!
          posted @ 2008-03-01 17:11 Super·shen BLOG 閱讀(1742) | 評(píng)論 (1)編輯 收藏

          [轉(zhuǎn)自] http://webdn.trueself.cn/archives/107

          posted @ 2008-02-28 14:19 Super·shen BLOG 閱讀(746) | 評(píng)論 (0)編輯 收藏

          ◆ 使用strtok函數(shù)分割。
               原型:char *strtok(char *s, char delim);
              strtok在s中查找包含在delim中的字符并用NULL('\0')來替換,直到找遍整個(gè)字符串。  
               功能:分解字符串為一組字符串。s為要分解的字符串,delim為分隔符字符串。
              說明:首次調(diào)用時(shí),s指向要分解的字符串,之后再次調(diào)用要把s設(shè)成NULL。
                          strtok在s中查找包含在delim中的字符并用NULL('\0')來替換,直到找遍整個(gè)字符串。
              返回值:從s開頭開始的一個(gè)個(gè)被分割的串。當(dāng)沒有被分割的串時(shí)則返回NULL。
                            所有delim中包含的字符都會(huì)被濾掉,并將被濾掉的地方設(shè)為一處分割的節(jié)點(diǎn)。

          使用例:
          #include <stdio.h>
          #include <string.h>
          #include <stdio.h>
          #include <string.h>

          int main(int argc,char **argv)
          {
              char * buf1="aaa, ,a, ,,,bbb-c,,,ee|abc";

              /* Establish string and get the first token: */
              char* token = strtok( buf1, ",-|");
              while( token != NULL )
               {
                     /* While there are tokens in "string" */
                     printf( "%s ", token );
                    /* Get next token: */
                    token = strtok( NULL, ",-|");
               }
              return 0;
          }

          OUT 值:
          aaa

          a

          bbb
          c
          ee
          abc

          ◆ 使用strstr函數(shù)分割。

              原型:extern char *strstr(char *haystack,char *needle);

              用法:#include <string.h>
             功能:從字符串haystack中尋找needle第一次出現(xiàn)的位置(不比較結(jié)束NULL)
             說明:返回指向第一次出現(xiàn)needle位置的指針,如果沒找到則返回NULL。

          使用例:
          #include <stdio.h>
          #include <string.h>

          int main(int argc,char **argv)
          {
               char *haystack="aaa||a||bbb||c||ee||";
               char *needle="||";
               char* buf = strstr( haystack, needle);
               while( buf != NULL )
               {
                   buf[0]='\0';
                   printf( "%s\n ", haystack);
                    haystack = buf + strlen(needle);
                    /* Get next token: */
                    buf = strstr( haystack, needle);
               }
               return 0;
          }

          OUT 值:
          aaa
          a
          bbb
          c
          ee

          ◆ strtok比較適合多個(gè)字符作分隔符的場(chǎng)合,而strstr適合用字符串作分隔符的場(chǎng)合。

          posted @ 2008-02-27 16:35 Super·shen BLOG 閱讀(1475) | 評(píng)論 (0)編輯 收藏
          我們來看看到底如何從POST表單收集數(shù)據(jù)到CGI程序,下面給出了一個(gè)比較簡單的C源代碼:     
              
           

           

          #include<stdio.h>
          #include<stdlib.h>    
          #define MAXLEN 80    
          #define EXTRA 5
          /*   4個(gè)字節(jié)留給字段的名字"data",   1個(gè)字節(jié)留給"="   */
          #define   MAXINPUT   MAXLEN+EXTRA+2 
          /*   1個(gè)字節(jié)留給換行符,還有一個(gè)留給后面的NULL   */
          #define DATAFILE "../data/data.txt"
          /*   要被添加數(shù)據(jù)的文件   */

          void   unencode(char   *src,   char   *last,   char   *dest)
          {
           for(; src != last; src++, dest++)
            if(*src == "+")
             *dest = " ";
            else if(*src == "%") {    
             int   code;    
             if(sscanf(src+1,"%2x",&code)!=1)code="?";
             *dest=code;
             src   +=2;}
            else
             *dest=*src;
            *dest=" ";
            *++dest="";    
          }    

          int   main(void)    
          {    
           char *lenstr;
           char input[MAXINPUT], data[MAXINPUT];
           long len;
           
           printf("%s%c%c", "Content-Type:text/html;charset=gb2312",13,10);
           printf("<TITLE>Response</TITLE>");

           lenstr=getenv("CONTENT_LENGTH");
           if(lenstr==NULL || sscanf(lenstr,"%ld",&len)!=1 || len>MAXLEN)
            printf("<P>表單提交錯(cuò)誤");
           else{
            FILE *f;
            fgets(input,   len+1,   stdin);
            unencode(input+EXTRA,   input+len,   data);

            f =fopen(DATAFILE, "a");
            if(f == NULL)    
             printf("<P>對(duì)不起,意外錯(cuò)誤,不能夠保存你的數(shù)據(jù)");    
            else
             fputs(data,   f);    
            fclose(f);
            printf("<P>非常感謝,您的數(shù)據(jù)已經(jīng)被保存<BR>%s",data);    
           }    
           return   0;    
          }    

              
                 從本質(zhì)上來看,程序先從CONTENT_LENGTH環(huán)境變量中得到數(shù)據(jù)的字長,然后讀取相應(yīng)長度的字符串。因?yàn)閿?shù)據(jù)內(nèi)容在傳輸?shù)倪^程中是經(jīng)過了編碼的,所以必須進(jìn)行相應(yīng)的解碼。編碼的規(guī)則很簡單,主要的有這幾條:     

          1.   表單中每個(gè)每個(gè)字段用字段名后跟等號(hào),再接上上這個(gè)字段的值來表示,每個(gè)字段之間的內(nèi)容用&連結(jié);    2.   所有的空格符號(hào)用加號(hào)代替,所以在編碼碼段中出現(xiàn)空格是非法的;    
          3.   特殊的字符比如標(biāo)點(diǎn)符號(hào),和一些有特定意義的字符如“+”,用百分號(hào)后跟其對(duì)應(yīng)的ACSII碼值來表示。    

          例如:如果用戶輸入的是:     
             
          Hello   there!    

          那么數(shù)據(jù)傳送到服務(wù)器的時(shí)候經(jīng)過編碼,就變成了data=Hello+there%21   上面的unencode()函數(shù)就是用來把編碼后的數(shù)據(jù)進(jìn)行解碼的。在解碼完成后,數(shù)據(jù)被添加到data.txt文件的尾部,并在瀏覽其中回顯出來。    

          把文件編譯完成后,把它改名為collect.cgi后放在CGI目錄中就可以被表單調(diào)用了。下面給出了其相應(yīng)的表單:    

          <FORM   ACTION="/cgi-bin/collect.cgi"   METHOD="POST"   >
          <P>請(qǐng)輸入您的留言(最多80個(gè)字符):<BR>
          <INPUT   NAME="data"   SIZE="60"   MAXLENGTH="80"   ><BR>
          <INPUT   TYPE="SUBMIT"   VALUE="確定">
          </FORM   >    
             
             
                 事實(shí)上,這個(gè)程序只能作為例子,是不能夠正式的使用的。它漏掉了很關(guān)鍵的一個(gè)問題:當(dāng)有多個(gè)用戶同時(shí)像文件寫入數(shù)據(jù)是,肯定會(huì)有錯(cuò)誤發(fā)生。而對(duì)于一個(gè)這樣的程序而言,文件被同時(shí)寫入的幾率是很大的。因此,在比較正式的留言版程序中,都需要做一些更多的考慮,比如加入一個(gè)信號(hào)量,或者是借助于一個(gè)鑰匙文件等。因?yàn)槟侵皇蔷幊痰募记蓡栴},在這兒就不多說了。

          posted @ 2008-02-27 13:52 Super·shen BLOG 閱讀(2773) | 評(píng)論 (1)編輯 收藏
          啥都不說,直接看代碼!

          簡單輸出代碼

          #include <stdio.h>
          #include <stdlib.h>
          #include <string.h>
          void main()
          {
          printf("Content-type:text/html\n\n");

          printf("hello world!");

          fflush(stdout);

          }



          處理get代碼

          #include <stdio.h>
          #include <stdlib.h>
          int zmain(void)
          {char *data;
          long m,n;
          printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10);
          printf("<TITLE>Multiplication results</TITLE>\n");
          printf("<H3>Multiplication results</H3>\n");
          data = getenv("QUERY_STRING");
          if(data == NULL) 
          printf("<P>Error! Error in passing data from form to script.");
          else if(sscanf(data,"m=%ld&n=%ld",&m,&n)!=2) 
          printf("<P>Error! Invalid data. Data must be numeric.");
          else 
          printf("<P>The product of %ld and %ld is %ld.",m,n,m*n);
          return 0;
          }


          處理post代碼

          #include<stdio.h>
          #include<stdlib.h>
          void main()
          {
           int i,n;
           printf("Content-type:text/html\n\n");
           n=0;
           if(getenv("CONTENT_LENGTH"))
            n=atoi(getenv("CONTENT_LENGTH"));
           printf("%d",n);
           for(i=0;i<n;i++)
            putchar(getchar());
           putchar('\n');
           fflush(stdout);
          }



          還是代碼


          #include <stdio.h>
          #include <stdlib.h>
          #include <string.h>

          /* 轉(zhuǎn)換函數(shù)聲明 */
          int htoi(char *);

          /*  主函數(shù) */
          void zmain() {
           int i,n;
           char c;
           printf ("Content-type: text/html\n\n");
           n=0;
           if (getenv("CONTENT_LENGTH"))
            n=atoi(getenv("CONTENT_LENGTH"));
           for (i=0; i<n;i++){
            
            int is_eq=0; //判斷是否有等于號(hào)。
            
            c=getchar();
            switch(c){
            case '&':
             c='\n';
             break;
            case '+':
             c='+';
             break;
            case '%':
             {
              char s[3];
              s[0]=getchar();
              s[1]=getchar();
              s[2]=0;
              c=htoi(s);
              i+=2;
             }
             break;
            case '=':
             c='=';
             is_eq=1;
             break;
            };
            
            putchar(c);
            //if (is_eq) putchar(' ');
           }
           putchar ('\n');
           fflush(stdout);
          }

          /* 轉(zhuǎn)換為小寫 */
          int islower (int ch ) 

          {
              return (unsigned int) (ch - 'a') < 26u;
          }


          /* convert hex string to int 16進(jìn)制轉(zhuǎn)換成10進(jìn)制 */
          int htoi(char *s)

          {
           
           char *digits="0123456789ABCDEF";
           
           if(islower(s[0])) s[0]=toupper(s[0]);
           if(islower(s[1])) s[1]=toupper(s[1]);
           
           return 16 * (strchr(digits, s[0]) -strchr(digits,'0') ) +(strchr(digits,s[1])-strchr(digits,'0'));
           
          }


          #include<stdio.h>
          #include<stdlib.h>
          void zzzmain()
          {
           int i,n;
           printf("Content-type:text/html\n\n");
           n=0;
           if(getenv("CONTENT_LENGTH"))
            n=atoi(getenv("CONTENT_LENGTH"));
           printf("%d",n);
           for(i=0;i<n;i++)
            putchar(getchar());
           putchar('\n');
           fflush(stdout);
          }

           

          posted @ 2008-02-26 15:37 Super·shen BLOG 閱讀(751) | 評(píng)論 (0)編輯 收藏
          http://samhe.javaeye.com/blog/142416
          posted @ 2008-01-18 17:14 Super·shen BLOG 閱讀(313) | 評(píng)論 (0)編輯 收藏
          DWR(Direct Web Remoting)是一個(gè)WEB遠(yuǎn)程調(diào)用框架.利用這個(gè)框架可以讓AJAX開發(fā)變得很簡單.利用DWR可以在客戶端利用JavaScript直接調(diào)用服務(wù)端的Java方法并返回值給JavaScript就好像直接本地客戶端調(diào)用一樣(DWR根據(jù)Java類來動(dòng)態(tài)生成JavaScrip代碼).它的最新版本DWR0.6添加許多特性如:支持Dom Trees的自動(dòng)配置,支持Spring(JavaScript遠(yuǎn)程調(diào)用spring bean),更好瀏覽器支持,還支持一個(gè)可選的commons-logging日記操作.

          以上摘自open-open,它通過反射,將java翻譯成javascript,然后利用回調(diào)機(jī)制,輕松實(shí)現(xiàn)了javascript調(diào)用Java代碼。

          其大概開發(fā)過程如下:
          1.編寫業(yè)務(wù)代碼,該代碼是和dwr無關(guān)的。
          2.確認(rèn)業(yè)務(wù)代碼中哪些類、哪些方法是要由javascript直接訪問的。
          3.編寫dwr組件,對(duì)步驟2的方法進(jìn)行封裝。
          4.配置dwr組件到dwr.xml文件中,如果有必要,配置convert,進(jìn)行java和javascript類型互轉(zhuǎn)。
          5.通過反射機(jī)制,dwr將步驟4的類轉(zhuǎn)換成javascript代碼,提供給前臺(tái)頁面調(diào)用。
          5.編寫網(wǎng)頁,調(diào)用步驟5的javascript中的相關(guān)方法(間接調(diào)用服務(wù)器端的相關(guān)類的方法),執(zhí)行業(yè)務(wù)邏輯,將執(zhí)行結(jié)果利用回調(diào)函數(shù)返回。
          6.在回調(diào)函數(shù)中,得到執(zhí)行結(jié)果后,可以繼續(xù)編寫業(yè)務(wù)邏輯的相關(guān)javascript代碼。

          下面以用戶注冊(cè)的例子,來說明其使用。(注意,本次例子只是用于演示,說明DWR的使用,類設(shè)計(jì)并不是最優(yōu)的)。

          1.先介紹下相關(guān)的Java類

            User: 用戶類,
            public class User {
          //登陸ID,主鍵唯一
          private String id;
          //姓名
          private String name;
          //口令
          private String password;
          //電子郵件
          private String email;
                  
          //以下包含getXXX和setXXX方法
          .......
            }

            UserDAO:實(shí)現(xiàn)User的數(shù)據(jù)庫訪問,這里作為一個(gè)演示,編寫測(cè)試代碼
            public class UserDAO {
              //存放保存的數(shù)據(jù)
              private static Map dataMap = new HashMap();

              //持久用戶
              public boolean save(User user) {
                if (dataMap.containsKey(user.getId()))
                  return false;
                System.out.println("下面開始保存用戶");
                System.out.println("id:"+user.getId());
                System.out.println("password:"+user.getPassword());
                System.out.println("name:"+user.getName());
                System.out.println("email:"+user.getEmail());
                dataMap.put(user.getId(), user);
                System.out.println("用戶保存結(jié)束");
                return true;
              }

              //查找用戶
              public User find(String id) {
                return (User)dataMap.get(id);
              }
          }

            DWRUserAccess:DWR組件,提供給javascript訪問的。

            public class DWRUserAccess {

                UserDAO userDAO = new UserDAO();

                public boolean save(User user) {
                  return userDAO.save(user);
                }

                public User find(String id) {
                  return userDAO.find(id);
                }
            }
            

            下面說明下程序執(zhí)行的流程

            1.用戶在頁面上輸入相關(guān)注冊(cè)信息,id、name、password、email,點(diǎn)擊“提交”按鈕
            2.javascript代碼開始執(zhí)行,根據(jù)用戶填寫相關(guān)信息,通過dwr提供的DWRUserAccess.js里save的方法,調(diào)用服務(wù)器端的DWRUserAccess類save方法,將注冊(cè)信息保存。
            3.通過DWRUserAccess.jsp里的find方法,調(diào)用服務(wù)器端DWRUserAccess類里的find方法,執(zhí)行用戶信息查找。

            注意,在以上的執(zhí)行過程中,DWRUserAccess是供DWR調(diào)用的,是DWR組件,因此需要將DWRUserAccess類配置到dwr中。

            接下來講解本次dwr測(cè)試環(huán)境的配置。

            1.新建一個(gè)webapp,命名為testApp
            2.將dwr.jar拷貝到testApp的WEB-INF的lib目錄下
            3.編譯上面的User,UserDAO,DWRUserAccess類,放到classes目錄下
            4.在web.xml中配置servlet,適配路徑到dwr目錄下,如下所示
              <servlet>
              <servlet-name>dwr-invoker</servlet-name>
              <display-name>DWR Servlet</display-name>
              <description>Direct Web Remoter Servlet</description>
              <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
              <init-param>
                <param-name>debug</param-name>
                <param-value>true</param-value>
              </init-param>
              <init-param>
                <param-name>scriptCompressed</param-name>
                <param-value>false</param-value>
              </init-param>
              <load-on-startup>1</load-on-startup>
            </servlet>

            <servlet-mapping>
              <servlet-name>dwr-invoker</servlet-name>
              <url-pattern>/dwr/*</url-pattern>
            </servlet-mapping>

            以上的配置可以攔截testApp下所有指向dwr的請(qǐng)求,關(guān)于這個(gè)攔截器,我們會(huì)在后面介紹。

            5.WEB-INF下新建一個(gè)dwr.xml文件,內(nèi)容如下:
            < xml version="1.0" encoding="UTF-8" >
          <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd">

          <dwr>
            <allow>
          <create creator="new" javascript="DWRUserAccess">
                <param name="class" value="test.DWRUserAccess"/>
              </create>
          <convert converter="bean" match="test.User"/>
            </allow>
          </dwr>

            這里我們把DWRUserAccess配置到了dwr中,create元素中,creater="new"表示每調(diào)用一次DWRUserAccess時(shí),需要new一個(gè)這樣的類;javascript="DWRUserAccess",表示提供給前臺(tái)頁面調(diào)用的javascirpt文件是DWRUserAccess.js。

            convert元素用于數(shù)據(jù)類型轉(zhuǎn)換,即java類和javascript之間相互轉(zhuǎn)換,因?yàn)楹颓芭_(tái)交換的是User對(duì)象,因此需要對(duì)此使用bean轉(zhuǎn)換,我們將在后面介紹這個(gè)類。

            4.編寫測(cè)試的HTML頁面 test.html
             <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
          <HTML>
          <HEAD>
          <TITLE>DWR測(cè)試</TITLE>
          <meta http-equiv=Content-Type content="text/html; charset=gb2312">
          <script src="/oblog312/dwr/engine.js"></script>
          <script src="/oblog312/dwr/util.js"></script>
          <script src="/oblog312/dwr/interface/DWRUserAccess.js"></script>
          </HEAD>
          <BODY>
          <B>用戶注冊(cè)</B><br>
          ------------------------------------------------
          <Br>
          <form name="regForm">
          登陸ID:<input type="text" name="id"><br>
          口  令:<input type="password" name="password"><br>
          姓  名:<input type="text" name="name"><br>
          電子郵件:<input type="text" name="email"><br>
          <input type="button" name="submitBtn" value="提交" onclick="OnSave()"><br>
              </form>

          <br>
          <br><B>用戶查詢</B><br>
          ------------------------------------------------
          <Br>
          <form name="queryForm">
          登陸ID:<input type="text" name="id"><br>
          <input type="button" name="submitBtn" value="提交" onclick="OnFind()"><br>
          </form>
          <br>
          </BODY>
          </HTML>
          <SCRIPT LANGUAGE="JavaScript">
          <!--
          function saveFun(data) {
          if (data) {
            alert("注冊(cè)成功!");
          } else {
            alert("登陸ID已經(jīng)存在!");
          }
          }

          function OnSave() {
          var userMap = {};
          userMap.id = regForm.id.value;
          userMap.password = regForm.password.value;
          userMap.name = regForm.name.value;
          userMap.email = regForm.email.value;
          DWRUserAccess.save(userMap, saveFun);
          }

          function findFun(data) {
          if (data == null) {
            alert("無法找到用戶:"+queryForm.id.value);
            return;
          }

          alert("找到用戶,nid:"+data.id+",npassword:"+data.password+",nname:"+data.name+",nemail:"+data.email);

          }

          function OnFind() {
          DWRUserAccess.find(queryForm.id.value, findFun);
          }
          //-->
          </SCRIPT>


          以下對(duì)頁面的javascript進(jìn)行解釋

          <script src="/oblog312/dwr/engine.js"></script>
          <script src="/oblog312/dwr/util.js"></script>
          這兩個(gè)是dwr提供的,用戶可以不必關(guān)心,只需要導(dǎo)入即可

          <script src="/oblog312/dwr/interface/DWRUserAccess.js"></script>
          是我們編寫的DWRUserAccess類,經(jīng)dwr反射后,生成的javascript代碼,它和DWRUserAccess.java是對(duì)應(yīng)的,供用戶調(diào)用,實(shí)際上我們就是通過這個(gè)js文件去調(diào)用服務(wù)器端的DWRUserAccess類的。

          <SCRIPT LANGUAGE="JavaScript">
          <!--
          function saveFun(data) {
          if (data) {
            alert("注冊(cè)成功!");
          } else {
            alert("用戶名已經(jīng)存在!");
          }
          }

          function OnSave() {
          var userMap = {};
          userMap.id = regForm.id.value;
          userMap.password = regForm.password.value;
          userMap.name = regForm.name.value;
          userMap.email = regForm.email.value;
          DWRUserAccess.save(userMap, saveFun);
          }

          function findFun(data) {
          if (data == null) {
            alert("無法找到用戶:"+queryForm.id.value);
            return;
          }

          alert("找到用戶,nid:"+data.id+",npassword:"+data.password+",nname:"+data.name+",nemail:"+data.email);

          }

          function OnFind() {
          DWRUserAccess.find(queryForm.id.value, findFun);
          }
          //-->
          </SCRIPT>

          這段javascirpt代碼,我們來看下OnSave函數(shù),首先它構(gòu)造一個(gè)map,將表單數(shù)據(jù)都設(shè)置到map中,然后調(diào)用DWRUserAccess.save(userMap, saveFun),執(zhí)行save操作。大家可以注意到,服務(wù)器端的DWRUserAccess中的save方法是這樣的:boolean save(User user),其參數(shù)是一個(gè)User對(duì)象,返回一個(gè)boolean值;而客戶端的方法是這樣的:save(userMap,saveFun),第一個(gè)參數(shù)userMap是javascirpt中的map對(duì)象,在這里相當(dāng)于服務(wù)器端的User對(duì)象(在服務(wù)器端執(zhí)行時(shí),會(huì)通過convert轉(zhuǎn)換成User對(duì)象),前面我們提到dwr是利用回調(diào)函數(shù)來返回執(zhí)行結(jié)果的,第二個(gè)參數(shù)saveFun即是一個(gè)回調(diào)函數(shù)。在函數(shù)function saveFun(data)中,data是執(zhí)行結(jié)果,這里是一個(gè)bool值,非常簡單的,我們通過判斷data是否為真,可以知道用戶名是否重復(fù),用戶是否注冊(cè)成功。

          看一下OnFind查找函數(shù),執(zhí)行結(jié)果在回調(diào)函數(shù)findFun(data)中,因?yàn)榉?wù)器端返回的是一個(gè)User對(duì)象,通過convert,將會(huì)轉(zhuǎn)換成javascript的一個(gè)map對(duì)象,
          于是在findFun中,通過data.id、data.name、data.password、data.email我們可以輕松的訪問到這個(gè)User對(duì)象。


          好了配置完畢,啟動(dòng)服務(wù)器,在目錄中打入localhost/testApp/test.html。

          1.在“用戶注冊(cè)”表單中,id框中輸入admin,password中輸入123456,name中輸入chenbug,email中輸入chenbug@zj.com,點(diǎn)擊提交按鈕,彈出對(duì)話框:“注冊(cè)成功”,在服務(wù)器后臺(tái)可以看到信息如下:

          下面開始保存用戶
          id:admin
          password:123456
          name:chenbug
          email:chenbug@zj.com
          用戶保存結(jié)束

          再次點(diǎn)擊提交按鈕,彈出對(duì)話框“登陸ID已經(jīng)存在”。

          2.在“用戶查詢”對(duì)話框中,輸入登陸ID為admin,點(diǎn)擊提交按鈕,提示找到用戶,并顯示相關(guān)信息,輸入admin123,點(diǎn)擊提交按鈕,提示無法找到用戶。

          至此,測(cè)試結(jié)束。


          后續(xù):
          1。攔截器 uk.ltd.getahead.dwr.DWRServlet
          該類攔截所有指向dwr目錄下的請(qǐng)求,并調(diào)用Processor的handler方法進(jìn)行處理,在uk.ltd.getahead.dwr.impl.DefaultProcessor下,我們可以看到詳細(xì)的處理過程。
          if (pathInfo.length() == 0 ||
                      pathInfo.equals(HtmlConstants.PATH_ROOT) ||
                      pathInfo.equals(req.getContextPath()))
                  {
                      resp.sendRedirect(req.getContextPath() + servletPath + HtmlConstants.FILE_INDEX);
                  }
                  else if (pathInfo.startsWith(HtmlConstants.FILE_INDEX))
                  {
                      index.handle(req, resp);
                  }
                  else if (pathInfo.startsWith(HtmlConstants.PATH_TEST))
                  {
                      test.handle(req, resp);
                  }
                  else if (pathInfo.startsWith(HtmlConstants.PATH_INTERFACE))
                  {
                      iface.handle(req, resp);
                  }
                  else if (pathInfo.startsWith(HtmlConstants.PATH_EXEC))
                  {
                      exec.handle(req, resp);
                  }
                  else if (pathInfo.equalsIgnoreCase(HtmlConstants.FILE_ENGINE))
                  {
                      file.doFile(req, resp, HtmlConstants.FILE_ENGINE, HtmlConstants.MIME_JS);
                  }
                  else if (pathInfo.equalsIgnoreCase(HtmlConstants.FILE_UTIL))
                  {
                      file.doFile(req, resp, HtmlConstants.FILE_UTIL, HtmlConstants.MIME_JS);
                  }
                  else if (pathInfo.equalsIgnoreCase(HtmlConstants.FILE_DEPRECATED))
                  {
                      file.doFile(req, resp, HtmlConstants.FILE_DEPRECATED, HtmlConstants.MIME_JS);
                  }
                  else
                  {
                      log.warn("Page not found (" + pathInfo + "). In debug/test mode try viewing /[WEB-APP]/dwr/"); //$NON-NLS-1$ //$NON-NLS-2$
                      resp.sendError(HttpServletResponse.SC_NOT_FOUND);
                  }

          通過判斷request請(qǐng)求的servlet路徑,進(jìn)行處理,大家可以自己去參看,這里不詳細(xì)討論。


          2.bean轉(zhuǎn)換器,<convert converter="bean" match="test.User"/>
          將dwr.jar解壓縮,在路徑ukltdgetaheaddwr下可以看到dwr.xml,這里配置了系統(tǒng)默認(rèn)的一些轉(zhuǎn)換器,
          <converter id="bean" class="uk.ltd.getahead.dwr.convert.BeanConverter"/>即是剛才用到User類的轉(zhuǎn)換器,進(jìn)入代碼我們來看看它是如何在javascript和java間進(jìn)行轉(zhuǎn)換的。

          打開BeanConverter代碼,定位到函數(shù)

          public Object convertInbound(Class paramType, InboundVariable iv, InboundContext inctx) throws ConversionException

          即是將javascript對(duì)象轉(zhuǎn)換成java對(duì)象的,其中
          paramType即Class類型,在上面的例子中是test.User,
          InboundVariable iv,是傳入的值,通過iv.getValue可以得到傳入的javascript值串
          InboundContext inctx,是入口參數(shù)上下文,用于保存轉(zhuǎn)換的后java對(duì)象。

          因?yàn)榍芭_(tái)傳入的是一個(gè)javascript的map類型,而map肯定是以{開始和以}結(jié)束的,于是在這個(gè)函數(shù)一開始進(jìn)行了判斷
          if (!value.startsWith(ConversionConstants.INBOUND_MAP_START))
                  {
                      throw new IllegalArgumentException(Messages.getString("BeanConverter.MissingOpener", ConversionConstants.INBOUND_MAP_START)); //$NON-NLS-1$
                  }

                  if (!value.endsWith(ConversionConstants.INBOUND_MAP_END))
                  {
                      throw new IllegalArgumentException(Messages.getString("BeanConverter.MissingCloser", ConversionConstants.INBOUND_MAP_START)); //$NON-NLS-1$
                  }

          javascript中,map里各個(gè)項(xiàng)是用逗號(hào)連接的,如var userMap = {id:'admin',password:'123456',name:'chenbug',email:'chenbug@zj.com'};而每個(gè)項(xiàng)的鍵值對(duì)是用冒號(hào)連接的,
          在convertInbound函數(shù)的接下來的處理中,即是通過分析map字串,通過paramType構(gòu)造java實(shí)例(即User類),然后通過反射,將這些鍵值對(duì)設(shè)置到j(luò)ava實(shí)例中,并返回。
          這樣就完成了javascript到j(luò)ava的轉(zhuǎn)換。


          另一個(gè)函數(shù)
          public String convertOutbound(Object data, String varname, OutboundContext outctx) throws ConversionException

          即是將java對(duì)象轉(zhuǎn)換為javascript對(duì)象(其實(shí)是聲明和賦值語句)。
          Object data ,是待轉(zhuǎn)換的java對(duì)象
          String varname,是javascript中的該對(duì)象的變量名
          OutboundContext outctx,傳出參數(shù)上下文,用于保存轉(zhuǎn)換后的javascript值

          StringBuffer buffer = new StringBuffer();
                  buffer.append("var "); //$NON-NLS-1$
                  buffer.append(varname);
                  buffer.append("={};"); //$NON-NLS-1$
          這里聲明了map類型的變量。

          即下來來的代碼即是通過反射進(jìn)行變量賦值,如下
            buffer.append(varname);
                              buffer.append('.');
                              buffer.append(name);
                              buffer.append('=');
                              buffer.append(nested.getAssignCode());
                              buffer.append(';');
          大家可以自己去參看更多的代碼。

          3.dwr本身提供了一個(gè)測(cè)試環(huán)境,大家在配置完后,可以在IE中輸入地址http://localhost/testApp/dwr/index.html,看到配置的各DWR組件,并進(jìn)行相關(guān)測(cè)試。
          posted @ 2008-01-18 14:43 Super·shen BLOG 閱讀(41043) | 評(píng)論 (27)編輯 收藏

          1. dwr  - direct web remote
          2. 推技術(shù)
          3. http 長連接
          4. Comet  ----   HTTP長連接的“服務(wù)器推”技術(shù)
          5. Jetty服務(wù)器 ----  Jetty 6 Web 服務(wù)器針對(duì) AJAX、Comet 應(yīng)用的特點(diǎn)進(jìn)行了很多創(chuàng)新的改進(jìn),請(qǐng)參考文章“AJAX,Comet and Jetty”(請(qǐng)參見 參考資源)。


          http://wiki.javascud.org/display/dwrcn/Home
          http://wiki.springside.org.cn/display/springside/DWR

          http://blog.csdn.net/octverve/archive/2007/09/26/1801826.aspx
          posted @ 2008-01-15 10:07 Super·shen BLOG 閱讀(311) | 評(píng)論 (0)編輯 收藏

          學(xué)習(xí)共進(jìn)!

          MyEclipse 5.5 開發(fā) Struts 1.2 簡單登錄的入門視頻(有聲+源碼)
            2007-09-19 01:50

          視頻講解: Netbeans 5.5 配置顯示中文 JavaDoc

          入門視頻: 使用 MyEclipse 開發(fā) Swing 應(yīng)用

          河南話講解 MyEclipse + Tomcat Servlet 開發(fā)入門視頻

          MyEclipse + JPA + Toplink 開發(fā)視頻: 開發(fā)并運(yùn)行第一個(gè) JPA 項(xiàng)目

          MyEclipse + JBoss 開發(fā)視頻: 配置,開發(fā)并運(yùn)行第一個(gè) EJB 3 項(xiàng)目

          JDBC 入門視頻: 配置 SQL Explorer 插件, ODBC 數(shù)據(jù)源, 建表, 用 JDBC 讀取數(shù)據(jù)庫

          Tomcat 入門視頻: 下載, 運(yùn)行, 第一個(gè) HelloWorld

          Eclipse 入門視頻: 下載, 運(yùn)行, 第一個(gè) HelloWorld

          Java 入門視頻: 下載, 安裝 JDK, 配置環(huán)境變量, HelloWorld

          推薦給初學(xué)者的 Java 視頻

          Netbeans 6.0 M10 開發(fā) UML 項(xiàng)目的入門視頻

          MyEclipse UML 入門視頻2 - 根據(jù)代碼反向工程生成 UML

          MyEclipse UML 入門視頻

          MyEclipse + Tomcat 開發(fā)視頻: 下載,安裝,配置,開發(fā)并運(yùn)行Web項(xiàng)目

          小電影: 用 MyEclipse 開發(fā) Spring + Struts + Hibernate 的總結(jié)與操作視頻(9分鐘)

          小電影: 用 MyEclipse 開發(fā) Spring + Struts 的總結(jié)與操作視頻(7分鐘)

          用MyEclipse 4 分鐘開發(fā)Spring整合Hibernate應(yīng)用的視頻

          在 Linux 上配置并運(yùn)行 Tomcat 服務(wù)器(入門整理)(視頻)

          Java 初學(xué)者入門視頻: 下載 JDK 和 Netbeans

          Eclipse 配置顯示中文 javadoc 的視頻

          Hibernate 英文 PPT 及 MyEclipse 操作視頻整理

          推薦一點(diǎn) MyEclipse 的官方Spring,Hibernate入門視頻教程

          Netbeans 5.5 + JPA + Hibernate 3 + Tomcat 實(shí)例有聲視頻

          推薦一些AJAX視頻和文章

          夏昕 <<Spring 開發(fā)指南入門>>1 分鐘上手教程視頻(不帶解說)

          AJAX 入門培訓(xùn) PPT 及示例代碼

          Java EE 5 入門 PPT 講解有聲視頻 - 第二部分

          Java EE 5 入門 PPT 講解有聲視頻 - 第一部分

          Java EE 5 入門視頻 - 在 JSF 中使用 JPA

          Jigloo 開發(fā) Swing 的入門教程

          視頻:使用 Netbeans 5.5可視化開發(fā) JSF 的簡單注冊(cè)流程

          Java EE 5 入門視頻 - 在 J2SE 中使用 JPA

          Navicat管理Mysql 的視頻

          Weblogic 9 之旅圖文視頻 2 - Portal 開發(fā)環(huán)境設(shè)置, 簡單的Portal 開發(fā)(視頻已貼上)

          用 JProfiler4 調(diào)優(yōu) Weblogic 和 Tomcat 的視頻(原創(chuàng))

          來自 http://www.aygfsteel.com/beansoft

          posted @ 2008-01-08 10:05 Super·shen BLOG 閱讀(696) | 評(píng)論 (0)編輯 收藏
          String command = "cmd /c C:/Program Files/MySQL/MySQL Server 5.0/bin>mysqldump -h localhost -u root -p aijia > E:/aijia.dmp";
            try {
             Process process = Runtime.getRuntime().exec(command);
             InputStreamReader ir = new InputStreamReader(process
               .getInputStream());
             LineNumberReader input = new LineNumberReader(ir);
             String line;
             while ((line = input.readLine()) != null)
              System.out.println(line);
             input.close();
            } catch (IOException e) {
             e.printStackTrace();
            }




          另外

          首先,設(shè)置mysql的環(huán)境變量(在path中添加%MYSQL_HOME%\bin),重啟電腦。
          完整代碼:
              /**
               * @param args
               */
              public static void main(String[] args) {
                  /*
                   * 備份和導(dǎo)入是一個(gè)互逆的過程。
                   * 備份:程序調(diào)用mysql的備份命令,讀出控制臺(tái)輸入流信息,寫入.sql文件;
                   * 導(dǎo)入:程序調(diào)用mysql的導(dǎo)入命令,把從.sql文件中讀出的信息寫入控制臺(tái)的輸出流
                   * 注意:此時(shí)定向符">"和"<"是不能用的
                   */
                  backup();
                  load();
              }

              /**
               * 備份檢驗(yàn)一個(gè)sql文件是否可以做導(dǎo)入文件用的一個(gè)判斷方法:把該sql文件分別用記事本和ultra
               * edit打開,如果看到的中文均正常沒有亂碼,則可以用來做導(dǎo)入的源文件(不管sql文件的編碼格式如何,也不管db的編碼格式如何)
               */
              public static void backup() {
                  try {
                      Runtime rt = Runtime.getRuntime();

                      // 調(diào)用 mysql 的 cmd:
                      Process child = rt
                              .exec("mysqldump -u root --set-charset=utf8 bjse act_obj");// 設(shè)置導(dǎo)出編碼為utf8。這里必須是utf8
                     
                      // 把進(jìn)程執(zhí)行中的控制臺(tái)輸出信息寫入.sql文件,即生成了備份文件。注:如果不對(duì)控制臺(tái)信息進(jìn)行讀出,則會(huì)導(dǎo)致進(jìn)程堵塞無法運(yùn)行
                      InputStream in = child.getInputStream();// 控制臺(tái)的輸出信息作為輸入流
                                 
                      InputStreamReader xx = new InputStreamReader(in, "utf8");// 設(shè)置輸出流編碼為utf8。這里必須是utf8,否則從流中讀入的是亂碼
                     
                      String inStr;
                      StringBuffer sb = new StringBuffer("");
                      String outStr;
                      // 組合控制臺(tái)輸出信息字符串
                      BufferedReader br = new BufferedReader(xx);
                      while ((inStr = br.readLine()) != null) {
                          sb.append(inStr + "\r\n");
                      }
                      outStr = sb.toString();
                     
                      // 要用來做導(dǎo)入用的sql目標(biāo)文件:
                      FileOutputStream fout = new FileOutputStream(
                              "e:/mysql-5.0.27-win32/bin/bjse22.sql");
                      OutputStreamWriter writer = new OutputStreamWriter(fout, "utf8");
                      writer.write(outStr);
                      // 注:這里如果用緩沖方式寫入文件的話,會(huì)導(dǎo)致中文亂碼,用flush()方法則可以避免
                      writer.flush();

                      // 別忘記關(guān)閉輸入輸出流
                      in.close();
                      xx.close();
                      br.close();
                      writer.close();
                      fout.close();

                      System.out.println("/* Output OK! */");

                  } catch (Exception e) {
                      e.printStackTrace();
                  }

              }

              /**
               * 導(dǎo)入
               *
               */
              public static void load() {
                  try {
                      String fPath = "e:/mysql-5.0.27-win32/bin/bjse22.sql";
                      Runtime rt = Runtime.getRuntime();

                      // 調(diào)用 mysql 的 cmd:
                      Process child = rt.exec("mysql -u root bjse ");
                      OutputStream out = child.getOutputStream();//控制臺(tái)的輸入信息作為輸出流
                      String inStr;
                      StringBuffer sb = new StringBuffer("");
                      String outStr;
                      BufferedReader br = new BufferedReader(new InputStreamReader(
                              new FileInputStream(fPath), "utf8"));
                      while ((inStr = br.readLine()) != null) {
                          sb.append(inStr + "\r\n");
                      }
                      outStr = sb.toString();

                      OutputStreamWriter writer = new OutputStreamWriter(out, "utf8");
                      writer.write(outStr);
                      // 注:這里如果用緩沖方式寫入文件的話,會(huì)導(dǎo)致中文亂碼,用flush()方法則可以避免
                      writer.flush();
                      // 別忘記關(guān)閉輸入輸出流
                      out.close();
                      br.close();
                      writer.close();

                      System.out.println("/* Load OK! */");

                  } catch (Exception e) {
                      e.printStackTrace();
                  }

              }
          posted @ 2007-12-07 13:25 Super·shen BLOG 閱讀(5483) | 評(píng)論 (1)編輯 收藏
          用Flex/Central/Java上傳文件      
               in java:
          import com.oreilly.servlet.MultipartRequest;
          import javax.servlet.*;
          import javax.servlet.http.*;
          import java.io.IOException;
          import java.io.PrintWriter;

          public class UploadServlet extends HttpServlet {
              protected void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {;}

              protected void doPost( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {
                  MultipartRequest parts = new MultipartRequest( req, "C:\\MyUploadPath" );
                  PrintWriter out = res.getWriter();

                  out.print( "SUCCESS" );
                  out.close();
              }
          }

                in mxml:
          < mx:Application initialize="initApp( event )" xmlns:mx="http://www.macromedia.com/2003/mxml">
               < mx:Button id="btnUpload" label="Upload..." click="doUpload( event )" />
               < mx:Image id="imgUpload" width="100%" height="100%" horizontalAlign="center" />
          </mx:Application>

               as:

          private function doUpload( event:Object ):Void {
              var file:FileReference = new FileReference();

              // Ask the user to choose a file to upload
              if( file.browse( ["JPEG Files", "*.jpg"] ) ) {
                  file.addListener( this );
                  file.upload( "http://myurl/servlet/MyUploadServlet" );
              }
          }

          private function onUploadSuccess( ref:FileReference, response:String ):Void {
              imgUpload.source = "http://myurl/myfilepath/" + ref.name;
          }

          private function onUploadFailed( ref:FileReference, error:String, response:String ):Void {
              mx.controls.Alert.show( "Upload error: " + error );
          }

             

          servlet獲取絕對(duì)路徑方法:
          ServletConfig   config   =   this.getServletConfig();     
          ServletContext   context   =   getServletContext();   
          String   path   =   context.getRealPath("");  
          posted @ 2007-12-03 14:50 Super·shen BLOG 閱讀(1930) | 評(píng)論 (1)編輯 收藏
          用flex做即時(shí)通訊,收到的最新消息應(yīng)該在最下面,但textArea的滾動(dòng)條默認(rèn)在最上方,不方便查看最新消息。

          可以使用 maxVerticalScrollPosition屬性可以獲取最下方的值,非常方便


          另外提供類:

          package Util
          {
              import mx.controls.TextArea;

              public class ChatTextarea extends TextArea
              {
                  public function ChatTextarea()
                  {
                      super();
                  }
                 
                  override public function set htmlText( value:String ):void
                  {
                      super.htmlText = value;
                      this.validateNow();
                      if( textField ) verticalScrollPosition = textField.maxScrollV
                  }
                 
                  override public function set text( value:String ):void
                  {
                      super.htmlText = value;
                      this.validateNow();
                      if( textField ) verticalScrollPosition = textField.maxScrollV;
                  }
              }

          }
          posted @ 2007-11-22 16:34 Super·shen BLOG 閱讀(3125) | 評(píng)論 (0)編輯 收藏
          問題:

          然后運(yùn)行某Flex程序時(shí),出現(xiàn)如下提示:
          This content requires the Adobe Flash Player. Get Flash
          但是,鏈接到Adobe的Flash Player下載網(wǎng)頁,重裝了N次也不行。

          google到下面的信息:
          "...Flex Builder 2 裏面附的 debugger player 版次比正式版的 Flash Player 9 舊一點(diǎn),有時(shí)會(huì)導(dǎo)致網(wǎng)頁的自動(dòng)偵測(cè)失靈(誤以為user沒裝 flash player),所以現(xiàn)在 adobe 網(wǎng)頁上已經(jīng)有新版的 debugger player ,可以先試試裝那個(gè)版本看看。"


          實(shí)際解決方法:
          因?yàn)楸緳C(jī)已安裝了Flex bulider 3 , 既然知道問題所在,就不用再去down了,找到...\Flex bulider 3\Players\目錄,運(yùn)行Install Flash Player 9 ActiveX.msi,選擇Repair,出錯(cuò)失敗,再次選擇Remove卸載,重新安裝此ActiveX,瀏覽器中刷新mxml頁面,OK,搞定,收工。
          posted @ 2007-11-22 13:30 Super·shen BLOG 閱讀(1412) | 評(píng)論 (0)編輯 收藏

          已經(jīng)很久沒摸過FLASH了,由于要接一個(gè)項(xiàng)目需要用的flash實(shí)現(xiàn)。 當(dāng)我使用flash cs3 寫程序時(shí)發(fā)現(xiàn)已經(jīng)和以前的大不一樣了!多年沒接觸本來還想在友人面前顯耀一下寶刀未老,天哪,好多地方不一樣了,剛接觸還真不習(xí)慣,還出丑了。

          flash cs3  的改變?cè)醋杂?as3的重大改變。更源于flash player AM2的重大改變。

          as3功能很強(qiáng)大,語言和java類型,也是面向?qū)ο蟮模彩鞘褂锰摂M機(jī)解釋。 (虛擬機(jī)這個(gè)概念太強(qiáng)了。現(xiàn)在的主流程序都是用類似虛擬機(jī)技術(shù),JAVA  .NET  FLEX)

          實(shí)現(xiàn)技術(shù)原理 flash 和 java 曾經(jīng)紅火一時(shí)的applet 幾乎差不多了。但是flash更為簡單易用,易于入門!


          posted @ 2007-11-22 10:49 Super·shen BLOG 閱讀(315) | 評(píng)論 (0)編輯 收藏
               摘要: 如何解決端口沖突導(dǎo)致tomcat無法啟動(dòng)的問題 Tomcat在啟動(dòng)時(shí)主要使用下面的3個(gè)端口 <Server port="8005" shutdown="SHUTDOWN" debug="0"> <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8080" minProcessors=...  閱讀全文
          posted @ 2007-11-22 10:00 Super·shen BLOG 閱讀(16623) | 評(píng)論 (2)編輯 收藏
          自己在網(wǎng)上找了半天沒找到只有 “時(shí)分秒”的控件, 就自己做了個(gè),發(fā)在這里方便有人用到


          鼠標(biāo)點(diǎn)擊 后 的效果


          SetTime.js

          /**//***********************************
          * 簡單時(shí)間控件: version 1.0
          * 作者:李祿燊 
          * 時(shí)間:2007-10-31

          * 使用說明:
          * 首先把本控件包含到頁面 
          * <script src="XXX/setTime.js" type="text/javascript"></script>
          * 控件調(diào)用函數(shù):_SetTime(field)
          * 例如 <input name="time" type="text"   onclick="_SetTime(this)"/>
          *
          ***********************************
          */
          var str = "";
          document.writeln(
          "<div id=\"_contents\" style=\"padding:6px; background-color:#E3E3E3; font-size: 12px; border: 1px solid #777777;  position:absolute; left:?px; top:?px; width:?px; height:?px; z-index:1; visibility:hidden\">");
          str 
          += "\u65f6<select name=\"_hour\">";
          for (h = 0; h <= 9; h++) {
              str 
          += "<option value=\"0" + h + "\">0" + h + "</option>";
          }
          for (h = 10; h <= 23; h++) {
              str 
          += "<option value=\"" + h + "\">" + h + "</option>";
          }
          str 
          += "</select> \u5206<select name=\"_minute\">";
          for (m = 0; m <= 9; m++) {
              str 
          += "<option value=\"0" + m + "\">0" + m + "</option>";
          }
          for (m = 10; m <= 59; m++) {
              str 
          += "<option value=\"" + m + "\">" + m + "</option>";
          }
          str 
          += "</select> \u79d2<select name=\"_second\">";
          for (s = 0; s <= 9; s++) {
              str 
          += "<option value=\"0" + s + "\">0" + s + "</option>";
          }
          for (s = 10; s <= 59; s++) {
              str 
          += "<option value=\"" + s + "\">" + s + "</option>";
          }
          str 
          += "</select> <input name=\"queding\" type=\"button\" onclick=\"_select()\" value=\"\u786e\u5b9a\" style=\"font-size:12px\" /></div>";
          document.writeln(str);
          var _fieldname;
          function _SetTime(tt) {
              _fieldname 
          = tt;
              
          var ttop = tt.offsetTop;    //TT控件的定位點(diǎn)高
              var thei = tt.clientHeight;    //TT控件本身的高
              var tleft = tt.offsetLeft;    //TT控件的定位點(diǎn)寬
              while (tt = tt.offsetParent) {
                  ttop 
          += tt.offsetTop;
                  tleft 
          += tt.offsetLeft;
              }
              document.all._contents.style.top 
          = ttop + thei + 4;
              document.all._contents.style.left 
          = tleft;
              document.all._contents.style.visibility 
          = "visible";
          }
          function _select() {
              _fieldname.value 
          = document.all._hour.value + ":" + document.all._minute.value + ":" + document.all._second.value;
              document.all._contents.style.visibility 
          = "hidden";
          }




          posted @ 2007-11-01 15:33 Super·shen BLOG 閱讀(11143) | 評(píng)論 (13)編輯 收藏

          下邊的所有都是自己對(duì)JAVA的理解不知道對(duì)不對(duì),有待于以后實(shí)踐驗(yàn)證

          用JAVA編程,無論是什么框架,什么庫,什么插件, 他們的也還是來自 最基本java類編程。

          比如,我猜想 TOMCAT服務(wù)器,也是由一個(gè)帶MAIN方法的類來啟動(dòng)的, 然后開通一個(gè)端口服務(wù)器,它的原理應(yīng)該和java socket server編程應(yīng)該是一個(gè)道理。主要是啟動(dòng)一些類,來接受客戶端的請(qǐng)求(容器的原理應(yīng)該是這樣吧)


          再說 servlet 也是基本的 JAVA類, 他們是受容器的管理,受到的是容器的調(diào)用(容器應(yīng)該也就是帶main的java類),并對(duì)客戶端產(chǎn)生相應(yīng)。

          還有像 jsp 的所謂表現(xiàn)層框架,最終也是調(diào)用到帶main函數(shù)的java類。 它的原理是 jsp編譯生產(chǎn) servlet ,servlet 最終還是依靠容器。
          其實(shí)我想,自己也可以開發(fā)一個(gè)表現(xiàn)層,只要能實(shí)時(shí)編譯成servlet,就能和jsp一樣的功能了。
          不過jsp是sun公司的標(biāo)準(zhǔn)產(chǎn)品,它的庫已經(jīng)集合在大多數(shù)容器上了,得到廣大容器的廣泛支持,出來得也早,用人也多,很少人想到要做新的表現(xiàn)層(如果沒什么好功能,就等于重復(fù)發(fā)明車輪)。

          FreeMarker 的原理也是一樣,簡單說它就是一個(gè)庫,你可以把它集合到容器里,得到容器的支持后,用FreeMarker 編寫的表現(xiàn)層就能實(shí)時(shí)編譯成servlet。  最后得到的和jsp 得到的是一個(gè)效果。
          FreeMarker 最終的結(jié)果還是容器調(diào)用。

          不過要做一個(gè)FreeMarker 可不簡單,要有好的想法,要不就和jsp功能重復(fù)了,沒價(jià)值。


          以上都是個(gè)人想出來的 不知道是否正確 有待于個(gè)人深入學(xué)習(xí)。



          posted @ 2007-09-17 11:46 Super·shen BLOG 閱讀(4470) | 評(píng)論 (5)編輯 收藏

          java 中文亂碼處理。

           
          參考
          http://china.eceel.com/article/study_for_character_encoding_java.htm
          http://upurban.com/bbs/viewtopic.php?t=246

          1。什么是utf-8,什么是ISO-8859-1,什么是GB2312,還有什么是unicode

          2。java 程序的字符的表示格式

          3。jsp 程序中文顯示處理實(shí)例

          3。1
          <%@ page  pageEncoding="ISO-8859-1"%>和<%@ page  pageEncoding="GB2312"%>和<%@ page 

          pageEncoding="UTF-8"%>各自的意思是什么,他們是否只對(duì)post提交有效!
          request.setCharacterEncoding("UTF-8")是什么意思?有什么區(qū)別?還有

          response.setCharacterEncoding("UTF-8"),優(yōu)先于下邊
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

          setCharacterEncoding()該函數(shù)用來設(shè)置http請(qǐng)求或者相應(yīng)的編碼。

          對(duì)于request,是指提交內(nèi)容的編碼,指定后可以通過getParameter()則直接獲得正確的字符串,如果不

          指定,則默認(rèn)使用iso8859-1編碼,需要進(jìn)一步處理。參見下述"表單輸入"。值得注意的是在執(zhí)行

          setCharacterEncoding()之前,不能執(zhí)行任何getParameter()。java doc上說明:This method must be

          called prior to reading request parameters or reading input using getReader()。而且,該指定

          只對(duì)POST方法有效,對(duì)GET方法無效。分析原因,應(yīng)該是在執(zhí)行第一個(gè)getParameter()的時(shí)候,java將會(huì)

          按照編碼分析所有的提交內(nèi)容,而后續(xù)的getParameter()不再進(jìn)行分析,所以setCharacterEncoding()無

          效。而對(duì)于GET方法提交表單是,提交的內(nèi)容在URL中,一開始就已經(jīng)按照編碼分析所有的提交內(nèi)容,

          setCharacterEncoding()自然就無效。

          對(duì)于response,則是指定輸出內(nèi)容的編碼,同時(shí),該設(shè)置會(huì)傳遞給瀏覽器,告訴瀏覽器輸出內(nèi)容所采用的

          編碼。
           
          3.2. jsp輸出

          指定文件輸出到browser是使用的編碼,該設(shè)置也應(yīng)該置于文件的開頭。例如:<%@ page

          contentType="text/html; charset= GBK" %>。該設(shè)置和response.setCharacterEncoding("GBK")等效。

           

          4。java EE程序利用過濾器 處理中文問實(shí)例
          提交數(shù)據(jù)的編碼格式
          tomcat默認(rèn)提交格式是ISO-8859-1
          可以通過設(shè)置過濾器(只針對(duì)post提交)或修改server.xml 的URIencoding 編碼格式(只針對(duì)get提交)

          達(dá)到你想要的 數(shù)據(jù)提交編碼格式。

           

          總結(jié)

          ---by mylu 18:26 2007-5-20

          posted @ 2007-05-20 22:36 Super·shen BLOG 閱讀(1525) | 評(píng)論 (0)編輯 收藏

          ORM
          Object Relation Mapping
          對(duì)象 關(guān)系 映射

          對(duì)象 指實(shí)體域?qū)ο?br />關(guān)系 關(guān)系數(shù)據(jù)


          模型

          概念模型(實(shí)體-屬性)
          關(guān)系數(shù)據(jù)模型(關(guān)系數(shù)據(jù)庫)
          域模型(對(duì)象)


          軟件分層

          v - 表述層
          c /

          ??? /業(yè)務(wù)層
          m- 持久層(hibernate 技術(shù)實(shí)現(xiàn))
          ??? \數(shù)據(jù)層


          mvc 對(duì)應(yīng) 各層次


          概念實(shí)體關(guān)系

          1對(duì)1
          1對(duì)多
          多對(duì)多


          表與表之間的關(guān)系 參照完整性

          外鍵
          多對(duì)多
          多對(duì)一


          域?qū)ο笾g的 關(guān)系

          關(guān)聯(lián) (一對(duì)一 一對(duì)多 多對(duì)多)
          依賴 (一個(gè)類需要訪問另外一個(gè)類)
          聚集 (一個(gè)類的對(duì)象是另一個(gè)類的一部分, 人和手)
          一般化 (繼承關(guān)系)


          域?qū)ο?br />?實(shí)體域?qū)ο? (實(shí)體EJB,POJO)
          過程域?qū)ο? (會(huì)話EJB,消息驅(qū)動(dòng)EJB,POJO)
          事件域?qū)ο? ()

          在hibernate中 一般只關(guān)注 實(shí)體域?qū)ο?和 過程域?qū)ο?/p>


          域?qū)ο蟮年P(guān)系

          ?域?qū)ο蟮年P(guān)聯(lián)關(guān)系 是有方向的
          體現(xiàn)在類的編碼不一樣的

          單向關(guān)聯(lián)
          雙向關(guān)聯(lián)

          ?


          域?qū)ο蟮某志没?br />把對(duì)象從內(nèi)存中 保存到持久化設(shè)備中去

          ORM 與? ORM模式
          ORM模式是一種持久化技術(shù),還有其他模式的持久化技術(shù)。如主動(dòng)域模式(BMP),JDO模式,CMP模式。


          域模型和數(shù)據(jù)模型的各個(gè)不匹配之處
          1,繼承
          2,多對(duì)多
          3,雙向
          4。粒度
          盡量少連接查詢,很消耗時(shí)間的操作

          ?


          創(chuàng)建持久化類


          1。持久化類符合javabean的規(guī)范,包含一些屬性 以及對(duì)應(yīng)的getxxx 色天下學(xué)習(xí)方法
          2。持久化類有一個(gè)id屬性,用來唯一表示類的每一個(gè)對(duì)象。 也叫OID 對(duì)象表示符
          3。Hibernate要求持久化類必須提供一個(gè)不帶參數(shù)的默認(rèn)構(gòu)造方法

          創(chuàng)建數(shù)據(jù)庫schema

          創(chuàng)建對(duì)象-關(guān)系映射文件

          (一般在eslispe中先創(chuàng)建數(shù)據(jù)庫 然后再創(chuàng)建持久化類以及映射文件)

          hibernate 映射類型


          hibernate的初始化

          static{

          try{
          //根據(jù)默認(rèn)位置的hibernate配置文件創(chuàng)建 configuration實(shí)例
          Configuration config = new Configuration();
          config.addClass(Customer.class);
          //創(chuàng)建SessionFactory 實(shí)例
          sessionFactory = config.buildSessinoFactroy();
          }catch(Exception e){e.printStackTrace();}
          }


          SessionFactory 接口

          一個(gè)SessionFactory 實(shí)例是對(duì)應(yīng)一個(gè)數(shù)據(jù)源的,應(yīng)用從SessionFactory 獲取session實(shí)例對(duì)象
          1線程安全的
          2重量級(jí)的,不能隨意創(chuàng)建和銷毀她的實(shí)例。

          Session 接口

          1 Session接口是hibernate應(yīng)用最為廣泛的接口。
          2 Session也被稱為持久化管理器,它提供和持久化相關(guān)的操作
          3 Session有以下特點(diǎn)
          ?a 不是線程安全的 所以應(yīng)避免多線程共用一個(gè)Session實(shí)例
          ?b Session實(shí)例是輕量級(jí)的,所謂輕量級(jí)是指他的創(chuàng)建和銷毀不需要消耗太多的資源。意味著程序中可以經(jīng)常創(chuàng)建和銷毀Session實(shí)例,保證不多線程使用Session對(duì)象。

          Session接口的常用方法:
          save()
          update()
          delete()
          load()

          Session執(zhí)行事務(wù)流程

          Session session = factory.openSession();
          Transaction tx;
          try{
          tx = session.beginTranscation();
          //執(zhí)行事務(wù)
          ...
          //提交事務(wù)
          tx.commit();
          }
          catche(Exception e)
          {//如果出現(xiàn)異常,撤消事務(wù)
          if(tx!=null)tx.rollback();
          throw e;
          }
          finally{
          session.close(); //不管事務(wù)是否成功,最后都要關(guān)閉session對(duì)象
          }
          }

          ?

          ?

          ?

          ?

          posted @ 2007-02-07 14:32 Super·shen BLOG 閱讀(413) | 評(píng)論 (0)編輯 收藏

          eXtremeComponents FAQ

          eXtremeComponents FAQ(中文版)

          Jeff Johnston

          Lucky

          冷月宮主

          版本0.1.0

          本文檔允許在遵守以下兩條原則的條件下被使用和傳播: 1)不能憑借本文檔索取任何費(fèi)用 2)以任何方式(印刷物或電子版)使用和傳播時(shí)本文檔時(shí),必須包含本版權(quán)申明

          (更新中...)


          eXtremeComponents FAQ(中文)


          1.?如何使用導(dǎo)出功能

          Q: 如何使用導(dǎo)出功能

          A: 為了使用導(dǎo)出功能,只需要在web.xml文件中加入eXtremeComponents的導(dǎo)出過濾器的配置,內(nèi)容如下:

          <filter>
          <filter-name>eXtremeExport</filter-name>
          <filter-class>org.extremecomponents.table.filter.ExportFilter</filter-class>
          <init-param>
          <param-name>responseHeadersSetBeforeDoFilter</param-name>
          <param-value>true</param-value>
          </init-param>
          </filter>
          <filter-mapping>
          <filter-name>eXtremeExport</filter-name>
          <url-pattern>/*</url-pattern>
          </filter-mapping>

          2.?傳入中文參數(shù)亂碼

          Q: 傳入中文參數(shù)亂碼,如下頁面:

          		<form id="form1" name="form1" method="post" action="應(yīng)用eXtremeTable的action或是結(jié)果頁面名">
          <select name="selecttype" size="6">
          <option value="第一個(gè)">第一個(gè)</option>
          <option value="第二個(gè)">第二個(gè)</option>
          <option value="第三個(gè)">第三個(gè)</option>
          </select>
          <input type="text" name="username" />
          <input type="submit" name="Submit" value="提交" />
          </form>

          當(dāng)你提交時(shí)含有eXtremeTable的結(jié)果頁面會(huì)自動(dòng)取得頁面上的表單參數(shù),那怕是經(jīng)過了action的mapping.findForward("forward"),在我的試用過程中到頁面上會(huì)出現(xiàn)傳遞過去的參數(shù),但出現(xiàn)了亂碼問題,使用查詢(filter)功能是的中文參數(shù)問題類似。

          A:

          1. 確認(rèn)服務(wù)器的參數(shù)是否設(shè)置了正確的編碼,如果使用Tomcat請(qǐng)確認(rèn)Server.xml:

             <Connector port="80" URIEncoding="UTF-8" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false"
            redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" disableUploadTimeout="true" />
          2. 添加編碼過濾器到你的應(yīng)用工程:

            /*
            * Copyright 1999-2001,2004 The Apache Software Foundation.
            *
            * Licensed under the Apache License, Version 2.0 (the "License");
            * you may not use this file except in compliance with the License.
            * You may obtain a copy of the License at
            *
            * http://www.apache.org/licenses/LICENSE-2.0
            *
            * Unless required by applicable law or agreed to in writing, software
            * distributed under the License is distributed on an "AS IS" BASIS,
            * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            * See the License for the specific language governing permissions and
            * limitations under the License.
            */


            package filters;


            import java.io.IOException;
            import javax.servlet.Filter;
            import javax.servlet.FilterChain;
            import javax.servlet.FilterConfig;
            import javax.servlet.ServletException;
            import javax.servlet.ServletRequest;
            import javax.servlet.ServletResponse;
            import javax.servlet.UnavailableException;


            /**
            * <p>Example filter that sets the character encoding to be used in parsing the
            * incoming request, either unconditionally or only if the client did not
            * specify a character encoding. Configuration of this filter is based on
            * the following initialization parameters:</p>
            * <ul>
            * <li><strong>encoding</strong> - The character encoding to be configured
            * for this request, either conditionally or unconditionally based on
            * the <code>ignore</code> initialization parameter. This parameter
            * is required, so there is no default.</li>
            * <li><strong>ignore</strong> - If set to "true", any character encoding
            * specified by the client is ignored, and the value returned by the
            * <code>selectEncoding()</code> method is set. If set to "false,
            * <code>selectEncoding()</code> is called <strong>only</strong> if the
            * client has not already specified an encoding. By default, this
            * parameter is set to "true".</li>
            * </ul>
            *
            * <p>Although this filter can be used unchanged, it is also easy to
            * subclass it and make the <code>selectEncoding()</code> method more
            * intelligent about what encoding to choose, based on characteristics of
            * the incoming request (such as the values of the <code>Accept-Language</code>
            * and <code>User-Agent</code> headers, or a value stashed in the current
            * user's session.</p>
            *
            * @author Craig McClanahan
            * @version $Revision: 1.3 $ $Date: 2004/02/28 03:35:22 $
            */

            public class SetCharacterEncodingFilter implements Filter {


            // ----------------------------------------------------- Instance Variables


            /**
            * The default character encoding to set for requests that pass through
            * this filter.
            */
            protected String encoding = null;


            /**
            * The filter configuration object we are associated with. If this value
            * is null, this filter instance is not currently configured.
            */
            protected FilterConfig filterConfig = null;


            /**
            * Should a character encoding specified by the client be ignored?
            */
            protected boolean ignore = true;


            // --------------------------------------------------------- Public Methods


            /**
            * Take this filter out of service.
            */
            public void destroy() {

            this.encoding = null;
            this.filterConfig = null;

            }


            /**
            * Select and set (if specified) the character encoding to be used to
            * interpret request parameters for this request.
            *
            * @param request The servlet request we are processing
            * @param result The servlet response we are creating
            * @param chain The filter chain we are processing
            *
            * @exception IOException if an input/output error occurs
            * @exception ServletException if a servlet error occurs
            */
            public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain)
            throws IOException, ServletException {

            // Conditionally select and set the character encoding to be used
            if (ignore || (request.getCharacterEncoding() == null)) {
            String encoding = selectEncoding(request);
            if (encoding != null)
            request.setCharacterEncoding(encoding);
            }

            // Pass control on to the next filter
            chain.doFilter(request, response);

            }


            /**
            * Place this filter into service.
            *
            * @param filterConfig The filter configuration object
            */
            public void init(FilterConfig filterConfig) throws ServletException {

            this.filterConfig = filterConfig;
            this.encoding = filterConfig.getInitParameter("encoding");
            String value = filterConfig.getInitParameter("ignore");
            if (value == null)
            this.ignore = true;
            else if (value.equalsIgnoreCase("true"))
            this.ignore = true;
            else if (value.equalsIgnoreCase("yes"))
            this.ignore = true;
            else
            this.ignore = false;

            }


            // ------------------------------------------------------ Protected Methods


            /**
            * Select an appropriate character encoding to be used, based on the
            * characteristics of the current request and/or filter initialization
            * parameters. If no character encoding should be set, return
            * <code>null</code>.
            * <p>
            * The default implementation unconditionally returns the value configured
            * by the <strong>encoding</strong> initialization parameter for this
            * filter.
            *
            * @param request The servlet request we are processing
            */
            protected String selectEncoding(ServletRequest request) {

            return (this.encoding);

            }


            }
          3. 在web.xml中添加編碼過濾器配置:

             <filter>
            <filter-name>Set Character Encoding</filter-name>
            <filter-class>filters.SetCharacterEncodingFilter</filter-class>
            <init-param>
            <param-name>encoding</param-name>
            <param-value>gb2312</param-value>
            </init-param>
            </filter>
            <filter-mapping>
            <filter-name>Set Character Encoding</filter-name>
            <url-pattern>/*</url-pattern>
            </filter-mapping>

          3.?導(dǎo)出時(shí)中文文件名亂碼

          Q:關(guān)于導(dǎo)出時(shí)中文文件名為亂碼的問題

          A: 這是個(gè)bug,建議使用英文文件名,主要原因還是編碼問題。我們現(xiàn)在正在想辦法解決。

          4.?導(dǎo)出時(shí)文件內(nèi)容亂碼

          Q:導(dǎo)出時(shí)文件內(nèi)容亂碼

          A:首先請(qǐng)確認(rèn)使用的是extremecomponents-1.0.1-M5-A4版以后的版本

          1. Excle: 導(dǎo)出為Excle的中文問題已經(jīng)修正,默認(rèn)的情況下支持導(dǎo)出中文,用戶不需要任何改動(dòng)
          2. PDF : 由于extremecomponents使用了FOP來生成PDF文件,F(xiàn)OP在導(dǎo)出中文內(nèi)容時(shí)會(huì)產(chǎn)生亂碼。具體的解決方案 大家可以參考最新eXtremeComponents包:支持 PDF中文導(dǎo)出

          5.?變量命名問題

          Q:當(dāng)變量名為"action",在IE下執(zhí)行產(chǎn)生javascript錯(cuò)誤

          A: 內(nèi)部使用了一些關(guān)鍵字,就目前我所知的為"action"、"submit"。建議大家命名時(shí)盡量避免,如果大家必須使用,則可以使用table標(biāo)簽的autoIncludeParameters參數(shù)設(shè)置為"false":

          autoIncludeParameters="false"

          6.?格式化輸出表單中的數(shù)據(jù)

          Q:怎么樣格式化輸出表單中的數(shù)據(jù)

          A: 你可以設(shè)置列的cell:

          1. 日期格式化: cell = " date " format = " yyyy-MM-dd "
          2. 數(shù)字格式化: cell="currency" format="###,###,##0.00"

          詳細(xì)信息請(qǐng)參考指南

          7.?加入鏈接

          Q:怎么樣加入鏈接

          A: 你可以參考下例:

                      <ec:table
          var="pres"
          items="presidents"
          action="${pageContext.request.contextPath}/compact.run"
          imagePath="${pageContext.request.contextPath}/images/table/compact/*.gif"
          view="compact"
          title="Compact Toolbar View"
          showTooltips="false"
          >
          <ec:exportPdf
          fileName="output.pdf"
          tooltip="Export PDF"
          headerColor="black"
          headerBackgroundColor="#b6c2da"
          headerTitle="Presidents"
          text="PDF"
          />
          <ec:exportXls
          fileName="output.xls"
          tooltip="Export Excel"
          text="XLS"
          />
          <ec:row>
          <ec:column property="fullName" title="Name">
          <a >${pres.fullName}</a>
          </ec:column>
          <ec:column property="nickName"/>
          <ec:column property="term"/>
          <ec:column property="born" cell="date"/>
          <ec:column property="died" cell="date"/>
          <ec:column property="career"/>
          </ec:row>
          </ec:table>

          8.?行高亮顯示

          Q: 我想使用行的高亮顯示如何設(shè)置

          A: 你只需要設(shè)置行標(biāo)簽的highlightRow屬性: highlightRow="true"。eXtremeComponents提供了很多接口允許用戶按照自己的習(xí)慣來進(jìn)行定制,包括:CSS、CELL、View。相關(guān)信息請(qǐng)參考指南。



          by lucky
          posted @ 2007-01-26 16:04 Super·shen BLOG 閱讀(281) | 評(píng)論 (0)編輯 收藏
          》對(duì)象之間方法調(diào)用,通過傳遞消息

          OOP使各個(gè)對(duì)象各司其職,分別負(fù)擔(dān)執(zhí)行一組相關(guān)的任務(wù),如果一個(gè)對(duì)象要依賴于一個(gè)不在其范圍內(nèi)的方法,它就需要訪問包含該方法的第二個(gè)對(duì)象,即第一個(gè)對(duì)象需要第二個(gè)對(duì)象執(zhí)行這個(gè)方法(或者叫方法調(diào)用) 利用OOP術(shù)語,叫做一個(gè)對(duì)象向另外一個(gè)對(duì)象發(fā)送消息。

          》對(duì)象的生成: 對(duì)象是在執(zhí)行過程中由其所屬的類動(dòng)態(tài)生成的。 一個(gè)類可以生成多個(gè)不同的對(duì)象。


          》 消息與方法的概念

          對(duì)象之間的傳遞通過消息傳遞完成

          一個(gè)發(fā)送消息的對(duì)象 發(fā)送的消息包含3個(gè)方面的內(nèi)容
          1,接受消息的對(duì)象
          2,接受對(duì)象應(yīng)用的方法。
          3,方法所需要的參數(shù)。

          》面向?qū)ο笞兂傻幕咎卣?br />1 封裝性 Encapsulation 把數(shù)據(jù)和操作組織在類內(nèi)
          2?繼承性 Inheritance 通過類的繼承關(guān)系
          3多態(tài)性Polymophism(在運(yùn)行的時(shí)候體現(xiàn)) ??A通過方法重裁 B通過方法重寫,子類覆蓋父類的方法(接口一個(gè)種特殊的類哦)

          posted @ 2007-01-24 17:47 Super·shen BLOG 閱讀(359) | 評(píng)論 (0)編輯 收藏
          域?qū)ο笾g的4種關(guān)系

          1。關(guān)聯(lián)

          指類之間的引用關(guān)系,是實(shí)體域?qū)ο蟮淖钇毡榈年P(guān)系。
          一對(duì)一、一對(duì)多、多對(duì)多關(guān)聯(lián)

          如果類A和類B關(guān)聯(lián),那么被引用的B將被定義為A的屬性。

          Customer? 與 Order 是一對(duì)多的關(guān)聯(lián)關(guān)系

          Order 類 包含 Customer類的 屬性

          Customer? 類 包含  集合 Order?


          2。依賴

          posted @ 2006-12-30 16:30 Super·shen BLOG 閱讀(244) | 評(píng)論 (0)編輯 收藏


          一個(gè)J2EE 工程中涉及的對(duì)象

          • 數(shù)據(jù)傳輸對(duì)象DTO
          • 業(yè)務(wù)對(duì)象BO (實(shí)體業(yè)務(wù)對(duì)象 過程業(yè)務(wù)對(duì)象 事件業(yè)務(wù)對(duì)象)
          • 數(shù)據(jù)訪問對(duì)象DAO

          ?


          概念

          持久化框架、ORM框架、DAO設(shè)計(jì)模式

          他們的關(guān)系是:ORM框架是一種持久化框架,DAO是用于實(shí)現(xiàn)持久化框架的一種設(shè)計(jì)模式。

          posted @ 2006-12-27 17:14 Super·shen BLOG 閱讀(414) | 評(píng)論 (0)編輯 收藏
          ?ActionErrors ? errors ? = ? null; ? ?
          ? errors ? = ? new ? ActionErrors(); ? ?
          ? errors.add("isExist", ? new ? ActionError("error.isExist"));???
          // errors.add("isExist", ? new ? ActionError("error.isExist"));???等效于errors.add("isExist", ? new ? ActionMessage("error.isExist"));????

          ? saveErrors(request, ? errors); ?
          ? return ? (mapping.findForward("failure"));???


          failure頁面里也定義了<html:errors?? name="isExist"/> ?
          ? ApplicationResources.properties里面也定義了error.isExist=user ? have ? already ? exist!!!???
          ? 運(yùn)行結(jié)果 跳轉(zhuǎn)到failure頁面,顯示“user ? have ? already ? exist!!!???”




          ActionErrors.GLOBAL_ERROR
          怎么理解
          它和我們使用普通的字符有什么區(qū)別啊

          部分代碼如下:
          err.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.logon"));
          err.add("errinfo", new ActionError("error.logon"));

          以上兩名有什么區(qū)別啊


          沒什么區(qū)別
          ActionErrors.GLOBAL_ERROR也是一個(gè)字符串。
          最好寫做ActionErrors.GLOBAL_ERROR
          不然的話可能會(huì)報(bào)錯(cuò)。


          posted @ 2006-12-20 18:03 Super·shen BLOG 閱讀(2597) | 評(píng)論 (3)編輯 收藏
          和女主角Action 對(duì)象共舞

          什么是Action?
          和常規(guī)的web 應(yīng)用相比,Struts Action 類工作起來就象一個(gè)小型的servlet。在大多數(shù)Java
          應(yīng)用中,諸如訪問業(yè)務(wù)層的任務(wù)、錯(cuò)誤處理等任務(wù)均是由servlet 承擔(dān)的。在一個(gè) Struts 應(yīng)
          用中,servlet 扮演著一個(gè)分派器的角色。而Action 對(duì)象則干實(shí)際的工作。象 servlets 一樣,
          Action 對(duì)象是多線程的。每個(gè)應(yīng)用只需要一個(gè)Action 類的實(shí)例。

          Action做些什么?

          一個(gè)典型的Action 的職責(zé)通常是:

          ?? ■校驗(yàn)前提條件或者聲明
          ?? ■調(diào)用需要的業(yè)務(wù)邏輯方法
          ?? ■檢測(cè)其它處理錯(cuò)誤
          ?? ■將控制路由到相關(guān)視圖


          檢驗(yàn)輸入: Action 需要做的就是確認(rèn)ActionForm 是否是需要的類型。

          調(diào)用邏輯業(yè)務(wù):

          Action 類是HTTP 與應(yīng)用系統(tǒng)中其它部分之間的適配器。最重要的是要避免將業(yè)務(wù)邏輯放入
          Action 之中。Action 類應(yīng)該只是簡單地收集業(yè)務(wù)方法需要的數(shù)據(jù)并傳遞它到具體的業(yè)務(wù)對(duì)
          象。如果你同時(shí)在編寫業(yè)務(wù)類和Action 類,可能會(huì)受到要將它們編寫在一起的誘惑。一定
          要抵擋這種誘惑,并且將業(yè)務(wù)方法放入Action 可調(diào)用的單獨(dú)的類之中。Java 虛擬機(jī)(JVM)
          針對(duì)這種方法調(diào)用作了優(yōu)化;性能損失可以忽略不計(jì)。
          同時(shí)你也得到了一些設(shè)計(jì)上的優(yōu)勢(shì)

          Action檢測(cè)錯(cuò)誤:
          Struts具有一個(gè)設(shè)計(jì)良好的錯(cuò)誤處理系統(tǒng),允許你可以:
          ??■ 同時(shí)截獲幾個(gè)錯(cuò)誤
          ??■ 在請(qǐng)求中傳遞錯(cuò)誤數(shù)據(jù)包
          ??■ 顯示本地化信息

          這個(gè)處理流程涉及到兩個(gè)對(duì)象 (ActionErrors 和 ActionError) 和一個(gè)注冊(cè)錯(cuò)誤的工
          具方法(saveErrors) 。其它兩個(gè)對(duì)象 (MessageResources 和 一個(gè)定制標(biāo)簽)則用來顯
          示錯(cuò)誤信息

          注冊(cè)錯(cuò)誤
          總體流程歸結(jié)為:
          ??1 創(chuàng)建一個(gè)空的ActionErrors 實(shí)例
          ??2 在錯(cuò)誤發(fā)生時(shí),為錯(cuò)誤信息添加關(guān)鍵字;
          ??3 檢查是否添加了某些信息
          ??4 保存ActionErrors 集合對(duì)象到請(qǐng)求中
          ??5 ?轉(zhuǎn)發(fā)控制到錯(cuò)誤頁面以顯示信息
          ??6? 否則,正常繼續(xù)

          例如
          ActionErrors?errors?=?new?ActionErrors();
          try?{
          //?*?調(diào)用業(yè)務(wù)對(duì)象?*
          }

          catch?(ModelException?e)?{
          errors.add(ActionErrors.GLOBAL_ERROR,
          new?ActionError("error.detail",e.getMessage()));
          }

          if?(!errors.empty())?{
          saveErrors(Request,?errors);
          return?(mapping.findForward("error"));
          }

          //?*?正常繼續(xù)?*

          posted @ 2006-12-14 10:32 Super·shen BLOG 閱讀(423) | 評(píng)論 (0)編輯 收藏
          用Struts開發(fā)Web應(yīng)用

          要使用Struts 開發(fā)web 應(yīng)用,開發(fā)人員將需要的超鏈接定義為ActionForward,HTML 表
          單定義為ActionForm,定制的服務(wù)器端動(dòng)作定義為Action 類。
          需要訪問JDBC 和EJB 的開發(fā)人員也可通過Action 對(duì)象進(jìn)行他們的工作。這樣,表現(xiàn)層不
          需要和Model 層打交道。Struts Action 對(duì)象將收集View 需要的數(shù)據(jù),然后將它們轉(zhuǎn)發(fā)到
          表現(xiàn)頁面。Struts 提供 JSP 標(biāo)記庫,它們將和JSP 頁面一起使用,簡化 HTML 表單和訪
          問Action 要轉(zhuǎn)發(fā)的其它數(shù)據(jù)。其它表現(xiàn)機(jī)制,比如Velocity templates, 也可用來訪問
          Struts 框架,以創(chuàng)建動(dòng)態(tài)的web 頁面。這種處理流程入下圖:{D99B93EF-D27B-42BA-A010-CB465E53C7BD}.BMP



          {A1ABCBA2-B893-4911-8786-5CF86A796AFB}.JPG
          posted @ 2006-12-06 17:50 Super·shen BLOG 閱讀(290) | 評(píng)論 (0)編輯 收藏

          ?

          Java本身就支持多國語言編碼,不需要寫任何程序,可以很簡單的
          實(shí)現(xiàn)。
          秘訣就是兩點(diǎn):

          1、所有HTML/JSP頁面全部采用UTF-8編碼

          2、客戶端瀏覽器完全支持UTF-8編碼

          步驟:
          1、首先把所有的HTML/JSP的ContentType都設(shè)為UTF-8

          2、然后對(duì)于JSP程序中的非ASCII碼提示信息都不應(yīng)該寫在程序里面,都應(yīng)該放在
          application.properties里面統(tǒng)一管理。

          3、對(duì)HTML用native2ascii工具統(tǒng)一做一次處理,把HTML中的非ASCII碼都轉(zhuǎn)換為Unicode編碼。

          4、針對(duì)不同的語言,寫不同的application.properties,比如說簡體中文是
          application_zh_CN.properties,繁體中文是application_zh_TW.properties這樣,然后對(duì)這些配置信
          息文件同樣用native2ascii工具處理一次,把非ASCII碼統(tǒng)統(tǒng)轉(zhuǎn)為Unicode編碼。

          5、在Servlet的request.getCharacterEncoding()獲得客戶端的操作系統(tǒng)默認(rèn)編碼,然后set到Struts
          的HTTPSession的Locale中。

          OK!現(xiàn)在不同的客戶訪問,就會(huì)顯示不同的語言版本了。你可以看看此時(shí)你的瀏覽器的字符集,就是
          UTF-8。現(xiàn)在你的網(wǎng)站和Google一樣了,嘿嘿,其實(shí)你有心的話,看看你的瀏覽器訪問Google的時(shí)候是
          什么字符集吧

          切記:所有的HTML/JSP都要設(shè)為UTF-8編碼,所有的文件中的非ASCII碼字符都要用native2ascii工具轉(zhuǎn)
          為用ASCII表示的Unicode編碼。
          ----------------------------------------
          ----------------------------------------
          原創(chuàng)
          ----------------------------------------
          上面所述是我從網(wǎng)上下的一篇于中文問題的解決方案,確切的說應(yīng)該是關(guān)于Struts的國際化問題,下面我結(jié)合我的實(shí)踐談?wù)劸唧w如何實(shí)現(xiàn)Struts的國際化問題,我對(duì)理論不是非常精通,我只能完全憑自己的理解和實(shí)踐來講述,所以下面講的內(nèi)容可能不是非常正確,還請(qǐng)大家原諒。但有一點(diǎn)可以肯定,我通過自己的努力解決了Struts的中文問題,并實(shí)現(xiàn)Struts的國際化,其實(shí)一切并不復(fù)雜,下面是具體步驟:

          0.遇到的問題(這些問題也許不會(huì)同時(shí)出現(xiàn))
          a.中文數(shù)據(jù)從數(shù)據(jù)庫中到j(luò)sp中后就變成了"????"
          b.做好的中文properties文件,其中的中文value在頁面顯示亂碼
          c.jsp文件中的中文到瀏覽器后顯示時(shí)也是亂碼(建議不要在jsp文件中輸入中文,盡量放在properties文件中)
          d.由jsp傳給bean的中文值,再由bean傳回頁面又是亂碼
          e.當(dāng)更換本地瀏覽器的語言選項(xiàng)時(shí),Web應(yīng)用程序不能自動(dòng)根據(jù)你的locale選擇合適的*.properties文件。導(dǎo)致Web應(yīng)用程序不能國際化。
          1.環(huán)境:
          Web服務(wù)器: Tomcat 5.0.19
          操作系統(tǒng): Win2000 Server
          JVM : jdk 1.4
          數(shù) 據(jù) 庫: Oracle 8.1.7
          開發(fā)工具: struts studio 5.2 pro for eclipse
          2.先將所有*.jsp 網(wǎng)頁中開頭處加入

          <%@ page language="java" contentType="text/html; charset=utf-8" %>
          再設(shè)置<html:html locale = "true">

          3.然后編輯好兩個(gè)*.properties文件,放在classes文件夾下你指定的地方,這里是放在/web-inf/classes/com/wiley 下,它們分別是:

          ApplicationResources.properties (英文資源文件)
          ApplicationResources_zh.properties (中文資源文件)
          隨便用什么工具編寫都行啊!
          4.將ApplicationResources_zh.properties轉(zhuǎn)碼成gb2312。上面引文說要轉(zhuǎn)成UTF-8,結(jié)果我試了,不行。轉(zhuǎn)成gb2312就行了,操作是。
          將ApplicationResources_zh.properties更名為ApplicationResources_xx.properties
          在DOS命令行進(jìn)入ApplicationResources_xx.properties所在的文件夾
          使用命令:native2ascii -encoding gb2312 ApplicationResources_xx.properties ApplicationResources_zh.properties(至于你為什么會(huì)出現(xiàn)“native2ascii不是內(nèi)部命令”,,請(qǐng)查其它資料,可能你要設(shè)置環(huán)境變量,因?yàn)樗莏dk的文件夾bin下的一個(gè)應(yīng)用程序)
          5.接下來配置struts-config.xml,很簡單,我們加入:

          <message-resources parameter="com.wiley.ApplicationResources"/> 就行了;

          到此已能解決大多數(shù)中文問題。如上面所說的a,b,e 現(xiàn)在打開瀏覽器,選擇菜單:工具》internet選項(xiàng)》語言,將“中文-中國[zh-cn]”刪掉,添加一個(gè)“英語-英國[zh-gb]”確定后,重啟Tomcat,輸入網(wǎng)址你就會(huì)發(fā)現(xiàn),你的頁面的文本信息就會(huì)用的是ApplicationResources.properties (英文資源文件)中的內(nèi)容。如果換回“中文-中國[zh-cn]”,它就會(huì)顯示ApplicationResources_zh.properties (中文資源文件)中的中文內(nèi)容。

          至于問題“c.jsp文件中的中文到瀏覽器后顯示時(shí)也是亂碼” 你就要用與第4步類似的方法來重新對(duì)*.jsp 文件編碼,這時(shí)-encoding的參數(shù)就要用UTF-8了,如果你用的也是struts studio 5.2 pro for eclipse工具,這一步就免了。它會(huì)自動(dòng)用UTF-8的格式存儲(chǔ)。
          至于問題“d.由jsp傳給bean的中文值,再由bean傳回頁面又是亂碼”的解決,我只是加了個(gè)過濾器。
          你可以現(xiàn)在web.xml中加入:
          <filter>
          <filter-name>Set Character Encoding</filter-name>
          <filter-class>com.wiley.SetCharacterEncodingFilter</filter-class>
          <init-param>
          <param-name>encoding</param-name>
          <param-value>utf-8</param-value>
          </init-param>
          <init-param>
          <param-name>ignore</param-name>
          <param-value>true</param-value>
          </init-param>
          </filter>
          <filter-mapping>
          <filter-name>Set Character Encoding</filter-name>
          <servlet-name>action</servlet-name>
          </filter-mapping>

          然后在你指定的包內(nèi)加個(gè)java文件 我放在了/web-inf/classes/com/wiley 里,下面是源代碼:
          /*
          * XP Forum
          *
          * Copyright (c) 2002-2003 RedSoft Group. All rights reserved.
          *
          */
          package com.huahang.tj.struts.filters;

          import javax.servlet.*;
          import java.io.IOException;

          /**
          * <p>Filter that sets the character encoding to be used in parsing the
          * incoming request, either unconditionally or only if the client did not
          * specify a character encoding. Configuration of this filter is based on
          * the following initialization parameters:</p>
          * <ul>
          * <li><strong>encoding</strong> - The character encoding to be configured
          * for this request, either conditionally or unconditionally based on
          * the <code>ignore</code> initialization parameter. This parameter
          * is required, so there is no default.</li>
          * <li><strong>ignore</strong> - If set to "true", any character encoding
          * specified by the client is ignored, and the value returned by the
          * <code>selectEncoding()</code> method is set. If set to "false,
          * <code>selectEncoding()</code> is called <strong>only</strong> if the
          * client has not already specified an encoding. By default, this
          * parameter is set to "true".</li>
          * </ul>
          *
          * <p>Although this filter can be used unchanged, it is also easy to
          * subclass it and make the <code>selectEncoding()</code> method more
          * intelligent about what encoding to choose, based on characteristics of
          * the incoming request (such as the values of the <code>Accept-Language</code>
          * and <code>User-Agent</code> headers, or a value stashed in the current
          * user′s session.</p>
          *
          * @author <a href="mailto:jwtronics@yahoo.com">John Wong</a>
          *
          * @version $Id: SetCharacterEncodingFilter.java,v 1.1 2002/04/10 13:59:27 johnwong Exp $
          */
          public class SetCharacterEncodingFilter implements Filter {

          // ----------------------------------------------------- Instance Variables


          /**
          * The default character encoding to set for requests that pass through
          * this filter.
          */
          protected String encoding = null;


          /**
          * The filter configuration object we are associated with. If this value
          * is null, this filter instance is not currently configured.
          */
          protected FilterConfig filterConfig = null;


          /**
          * Should a character encoding specified by the client be ignored?
          */
          protected boolean ignore = true;


          // --------------------------------------------------------- Public Methods


          /**
          * Take this filter out of service.
          */
          public void destroy() {

          this.encoding = null;
          this.filterConfig = null;

          }


          /**
          * Select and set (if specified) the character encoding to be used to
          * interpret request parameters for this request.
          *
          * @param request The servlet request we are processing
          * @param result The servlet response we are creating
          * @param chain The filter chain we are processing
          *
          * @exception IOException if an input/output error occurs
          * @exception ServletException if a servlet error occurs
          */
          public void doFilter(ServletRequest request, ServletResponse response,
          FilterChain chain)
          throws IOException, ServletException {

          // Conditionally select and set the character encoding to be used
          if (ignore || (request.getCharacterEncoding() == null)) {
          String encoding = selectEncoding(request);
          if (encoding != null)
          request.setCharacterEncoding(encoding);
          }

          // Pass control on to the next filter
          chain.doFilter(request, response);

          }


          /**
          * Place this filter into service.
          *
          * @param filterConfig The filter configuration object
          */
          public void init(FilterConfig filterConfig) throws ServletException {

          this.filterConfig = filterConfig;
          this.encoding = filterConfig.getInitParameter("encoding");
          String value = filterConfig.getInitParameter("ignore");
          if (value == null)
          this.ignore = true;
          else if (value.equalsIgnoreCase("true"))
          this.ignore = true;
          else if (value.equalsIgnoreCase("yes"))
          this.ignore = true;
          else
          this.ignore = false;

          }


          // ------------------------------------------------------ Protected Methods


          /**
          * Select an appropriate character encoding to be used, based on the
          * characteristics of the current request and/or filter initialization
          * parameters. If no character encoding should be set, return
          * <code>null</code>.
          * <p>
          * The default implementation unconditionally returns the value configured
          * by the <strong>encoding</strong> initialization parameter for this
          * filter.
          *
          * @param request The servlet request we are processing
          */
          protected String selectEncoding(ServletRequest request) {

          return (this.encoding);

          }

          }//EOC
          到此我遇到的中文問題已全部得到解決,并從中理解到struts的國際化的深刻含義。
          我個(gè)人覺得struts作為一個(gè)功能強(qiáng)大的應(yīng)用框架,應(yīng)該早就考慮到它的國際化問題,并在實(shí)際應(yīng)用中不會(huì)很復(fù)雜,只要我們遵循一些規(guī)則,就可以盡情享受struts給我們帶來的無窮樂趣。希望以上所述對(duì)大家有所幫助。
          posted @ 2006-12-06 16:46 Super·shen BLOG 閱讀(302) | 評(píng)論 (0)編輯 收藏

          Cannot retrieve mapping for action

          異常
          javax.servlet.jsp.JspException: Cannot retrieve mapping for action /Login (/Login是你的action名字)




          可能原因
          action沒有再struts-config.xml 中定義,或沒有找到匹配的action,例如在JSP文件中使用 <html:form action="Login.do".將表單提交給Login.do處理,如果出現(xiàn)上述異常,請(qǐng)查看struts-config.xml中的定義部分,有時(shí)可能是打錯(cuò)了字符或者是某些不符合規(guī)則,可以使用struts console工具來檢查。





          Cannot retrieve definition for form bean null

          異常
          org.apache.jasper.JasperException: Cannot retrieve definition for form bean null

          可能原因

          這個(gè)異常是因?yàn)镾truts根據(jù)struts-config.xml中的mapping沒有找到action期望的form bean。大部分的情況可能是因?yàn)樵趂orm-bean中設(shè)置的name屬性和action中設(shè)置的name屬性不匹配所致。換句話說,action和form都應(yīng)該各自有一個(gè)name屬性,并且要精確匹配,包括大小寫。這個(gè)錯(cuò)誤當(dāng)沒有name屬性和action關(guān)聯(lián)時(shí)也會(huì)發(fā)生,如果沒有在action中指定name屬性,那么就沒有name屬性和action相關(guān)聯(lián)。當(dāng)然當(dāng)action制作某些控制時(shí),譬如根據(jù)參數(shù)值跳轉(zhuǎn)到相應(yīng)的jsp頁面,而不是處理表單數(shù)據(jù),這是就不用name屬性,這也是action的使用方法之一。





          No action instance for path /xxxx could be created

          異常
          No action instance for path /xxxx could be created

          可能原因
          特別提示:因?yàn)橛泻芏嘀星闆r會(huì)導(dǎo)致這個(gè)錯(cuò)誤的發(fā)生,所以推薦大家調(diào)高你的web服務(wù)器的日志/調(diào)試級(jí)別,這樣可以從更多的信息中看到潛在的、在試圖創(chuàng)建action類時(shí)發(fā)生的錯(cuò)誤,這個(gè)action類你已經(jīng)在struts-config.xml中設(shè)置了關(guān)聯(lián)(即添加了<action>標(biāo)簽)。

          在struts-config.xml中通過action標(biāo)簽的class屬性指定的action類不能被找到有很多種原因,例如:

          定位編譯后的.class文件失敗。Failure to place compiled .class file for the action in the classpath (在web開發(fā)中,class的的位置在r WEB-INF/classes,所以你的action class必須要在這個(gè)目錄下。例如你的action類位于WEB-INF/classes/action/Login.class,那么在struts-config.xml中設(shè)置action的屬性type時(shí)就是action.Login).
          拼寫錯(cuò)誤,這個(gè)也時(shí)有發(fā)生,并且不易找到,特別注意第一個(gè)字母的大小寫和包的名稱。

          在struts-config.xml中指定的action類沒有繼承自Stuts的Action類,或者你自定義的Action類沒有繼承自Struts提供的Action類。

          你的action類必須繼承自Struts提供的Action類。

          你的classpath的問題。例如web server沒有發(fā)現(xiàn)你的資源文件,資源文件必須在WEB-INF/classes/目錄下。

          Problem in struts-config.xml file with action mapping.

          Problem with data-sources.xml file.

          相關(guān)鏈接
          http://www.mail-archive.com/struts-user ... org/msg65874.html
          Action Mapping mistake in struts-config.xml:
          http://www.manning.com/ao/readforum.ht ... mp;readthread=177
          data-sources.xml file?:
          http://www.caucho.com/quercus/faq/section.xtp?section_id=30





          No getter method for property XXXX of bean org.apache.struts.taglib.html.BEAN

          異常
          javax.servlet.jsp.JspException: No getter method for property username of bean org.apache.struts.taglib.html.BEAN

          可能原因
          沒有位form bean中的某個(gè)變量定義getter 方法

          這個(gè)錯(cuò)誤主要發(fā)生在表單提交的FormBean中,用struts標(biāo)記<html:text property=”username”>時(shí),在FormBean中必須有一個(gè)getUsername()方法。注意字母“U”。

          Related Links
          Case can trip up the matching between get method's name and name specified in Struts tag
          http://saloon.javaranch.com/cgi-bin/ubb/ultimate ... c&f=58&t=000163





          java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm

          錯(cuò)誤
          java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm

          可能原因
          這個(gè)錯(cuò)誤主要發(fā)生在在classpath中找不到相應(yīng)的Java .class文件。如果這個(gè)錯(cuò)誤發(fā)生在web應(yīng)用程序的運(yùn)行時(shí),主要是因?yàn)橹付ǖ腸lass文件不在web server的classpath中(/WEB-INF/classes 和 /WEB-INF/lib)。

          在上面的錯(cuò)誤中,原因是找不到ActionForm類。

          This error is sometimes seen when one or more ActionForm.class instances are actually in the classpath. This most often occurs when ActionForm.class is made available correctly by placing struts.jar in the /WEB-INF/lib directory. When this library has been correctly placed and it is verified that ActionForm.class actually is present in the struts.jar file, the problem is either that more than one copy of ActionForm.class is in the classpath or (more likely) that duplicate versions of class files other than ActionForm are in the same classpath, causing confusion. This is especially true if a class that extends ActionForm is made available twice, such as in an .ear file that encompasses a .war file as well as in the .war file's own classpath (/WEB-INF/classes). This problem can be resolved by guaranteeing that there are no redundant classes, especially those related to Struts (directly from Struts or extensions of Struts), in the web application's view.

          相關(guān)連接
          EJB and Web Shared Links:
          http://forum.java.sun.com/thread.jsp?forum=26&am ... ;tstart=0&trange=15
          Keep Action and ActionForm (and their children) as non-overlapping unit(s) of an application
          http://www.mail-archive.com/struts-u ... ache.org/msg47466.html
          http://www.mail-archive.com/struts-user ... org/msg47467.html





          Exception creating bean of class org.apache.struts.action.ActionForm: {1}

          異常
          javax.servlet.jsp.JspException: Exception creating bean of class org.apache.struts.action.ActionForm: {1}

          可能原因
          Instantiating Struts-provided ActionForm class directly instead of instantiating a class derived off ActionForm. This might occur implicitly if you specify that a form-bean is this Struts ActionForm class rather than specifying a child of this class for the form-bean.

          Not associating an ActionForm-descended class with an action can also lead to this error.

          Related Links






          Cannot find ActionMappings or ActionFormBeans collection

          Exception
          javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection

          可能原因
          不是標(biāo)識(shí)Struts actionServlet的<servlet>標(biāo)記就是映射.do擴(kuò)展名的<sevlet-mapping>標(biāo)記或者兩者都沒有在web.xml中聲明。

          在struts-config.xml中的打字或者拼寫錯(cuò)誤也可導(dǎo)致這個(gè)異常的發(fā)生。例如缺少一個(gè)標(biāo)記的關(guān)閉符號(hào)/>。最好使用struts console工具檢查一下。

          另外,load-on-startup必須在web.xml中聲明,這要么是一個(gè)空標(biāo)記,要么指定一個(gè)數(shù)值,這個(gè)數(shù)值用來表servlet運(yùn)行的優(yōu)先級(jí),數(shù)值越大優(yōu)先級(jí)越低。

          還有一個(gè)和使用load-on-startup有關(guān)的是使用Struts預(yù)編譯JSP文件時(shí)也可能導(dǎo)致這個(gè)異常。

          相關(guān)鏈接
          Explicitly Define <load-on-startup>
          http://saloon.javaranch.com/cgi-bin/ubb/ultim ... topic&f=50&t=001055
          http://threebit.net/tutorials/ejb/general/





          NullPointerException at ... RequestUtils.forwardURL

          異常
          java.lang.NullPointerException at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1223)

          可能原因
          在struts-config.xml中的forward元素缺少path屬性。例如應(yīng)該是如下形式:
          <forward name="userhome" path="/user/userhome.jsp"/>





          Cannot find bean org.apache.struts.taglib.html.BEAN in any scope

          Exception
          javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope




          Probable Causes
          試圖在Struts的form標(biāo)記外使用form的子元素。這常常發(fā)生在你在</html:form>后面使用Struts的html標(biāo)記。

          另外要注意可能你不經(jīng)意使用的無主體的標(biāo)記,如<html:form … />,這樣web 服務(wù)器解析時(shí)就當(dāng)作一個(gè)無主體的標(biāo)記,隨后使用的所有<html>標(biāo)記都被認(rèn)為是在這個(gè)標(biāo)記之外的,如又使用了<html:text property=”id”>

          還有就是在使用taglib引入HTML標(biāo)記庫時(shí),你使用的prefix的值不是html。

          相關(guān)連接
          Using form subelements outside of a form tag
          http://forum.java.sun.com/thread.jsp?thread= ... &message=1384153





          Missing message for key xx.xx.xx

          Exception
          javax.servlet.jsp.JspException: Missing message for key xx.xx.xx

          Probable Causes
          這個(gè)key的值對(duì)沒有在資源文件ApplicationResources.properties中定義。如果你使用eclipse時(shí)經(jīng)常碰到這樣的情況,當(dāng)項(xiàng)目重新編譯時(shí),eclipse會(huì)自動(dòng)將classes目錄下的資源文件刪除。

          資源文件ApplicationResources.properties 不在classpath中 應(yīng)將資源文件放到 WEB-INF/classes 目錄下,當(dāng)然要在struts-config.xml中定義)





          Cannot find message resources under key org.apache.struts.action.MESSAGE

          異常
          Cannot find message resources under key org.apache.struts.action.MESSAGE

          可能原因
          很顯然,這個(gè)錯(cuò)誤是發(fā)生在使用資源文件時(shí),而Struts沒有找到資源文件。

          Implicitly trying to use message resources that are not available (such as using empty html:options tag instead of specifying the options in its body -- this assumes options are specified in ApplicationResources.properties file)

          XML parser issues -- too many, too few, incorrect/incompatible versions

          Related Links
          Provide Struts with Resource Bundle
          http://threebit.net/tutorials/ejb/general/
          XML Parser Issues
          http://www.mail-archive.com/struts-user ... org/msg15779.html





          No input attribute for mapping path /loginAction

          錯(cuò)誤
          No input attribute for mapping path /xxxxAction

          可能原因e
          No input attribute in action mapping in struts-config.xml file for the action with the name specified in the error message. An input attribute is not required if form validation is not performed (either because the validate attribute is set to false or because the validation method in the relevant form class is not implemented. The input attribute specifies the page leading to this action because that page is used to display error messages from the form validation.

          Related Links






          Strange Output Characters

          錯(cuò)誤
          Strange and seemingly random characters in HTML and on screen, but not in original JSP or servlet.

          可能原因
          混和使用Struts的html:form標(biāo)記和標(biāo)準(zhǔn)的HTML標(biāo)記不正確。

          使用的編碼樣式在本頁中不支持。





          "Document contained no data" or no data rendered on page

          錯(cuò)誤
          "Document contained no data" in Netscape

          No data rendered (completely empty) page in Microsoft Internet Explorer

          可能原因
          使用一個(gè)Action的派生類而沒有實(shí)現(xiàn)perform()方法或execute()方法。在Struts1.0中實(shí)現(xiàn)的是perform()方法,在Struts1.1中實(shí)現(xiàn)的是execute()方法,但Struts1.1向后兼容perform()方法。

          但你使用Struts1.1創(chuàng)建一個(gè)Action的派生類,并且實(shí)現(xiàn)了execute()方法,而你在Struts1.0中運(yùn)行的話,就會(huì)得到"Document contained no data" error message in Netscape or a completely empty (no HTML whatsoever) page rendered in Microsoft Internet Explorer.”的錯(cuò)誤信息。


          posted @ 2006-12-06 16:44 Super·shen BLOG 閱讀(491) | 評(píng)論 (0)編輯 收藏
          Action類

          用來訪問業(yè)務(wù)邏輯類。當(dāng) ActionServlet 從容器接收到一個(gè)請(qǐng)求,它使用URI (或者路徑
          “path”) 來決定那個(gè)Action 將用來處理請(qǐng)求。一個(gè) Action 可以校驗(yàn)輸入,并且訪問業(yè)務(wù)
          層以從數(shù)據(jù)庫或其他數(shù)據(jù)服務(wù)中檢索信息。


          ActionForm類

          為校驗(yàn)輸入或者使用輸入來更新數(shù)據(jù)庫, Action 需要知道什么值被提交上來。它并不是強(qiáng)
          制每個(gè)Action 都要從請(qǐng)求中抓取這些值,而是由 ActionServlet 將輸入綁定到JavaBean中。
          輸入 bean 就是Struts ActionForm 類的子類。ActionServlet 通過查找請(qǐng)求的路徑可以決定使
          用哪個(gè)ActionForm , Action 也是通過同樣的方法選取的。ActionForm 擴(kuò)展了
          org.apache.struts.action.ActionForm 類

          每個(gè)請(qǐng)求都必須以HTTP 響應(yīng)進(jìn)行應(yīng)答。 通常,Struts Action 并不自行渲染響應(yīng)信息,
          而是將請(qǐng)求轉(zhuǎn)發(fā)到其他資源,比如JSP 頁面。Struts 提供一個(gè)ActionForward 類,用來將
          一個(gè)頁面的路徑保存為邏輯名稱。當(dāng)完成業(yè)務(wù)邏輯后,Action 選擇并向Servlet 返回一個(gè)
          ActionForward。Servlet 然后使用保存在ActionForward 對(duì)象中的路徑來調(diào)用頁面完成響
          應(yīng)。

          Struts 將這些細(xì)節(jié)都綁定在一個(gè)ActionMapping 對(duì)象中。每個(gè)ActionMapping 相對(duì)于一個(gè)
          特定的路徑。當(dāng)某個(gè)路徑被請(qǐng)求時(shí),Servlet 就查詢ActionMapping 對(duì)象。ActionMapping
          對(duì)象告訴servlet,哪些個(gè)Action,ActionForm,和 ActionForward 將要被本次請(qǐng)求使用。
          所有這些細(xì)節(jié),關(guān)于Action, ActionForm, ActionForward, ActionMapping,以及其
          它一些東西,都在struts-config.xml 文件中定義。 ActionServlet 在啟動(dòng)時(shí)讀取這個(gè)配置文
          件,并創(chuàng)建一個(gè)配置對(duì)象數(shù)據(jù)庫



          舉個(gè)例子來說,
          頁面上如果有以下語句:
          <html:form?action="/hello.do">
          當(dāng)submit此form時(shí),控制器從配置文件中找<action-mappings>下path="/hello"?的<action>元素
          然后根據(jù)此action元素的type屬性找要執(zhí)行的action類文件
          比如

          <action-mappings>
          ????<action?path="hello"
          ????????????type="cn.com.mylu.Hello"
          ????????????name="Hellofrom"
          ????????????……
          ????</action>

          其中 cn.com.mylu.Hellofrom?為ActionForm類javabean
          ???????????cn.com.mylu.Hello 為Action類

          ??? <form-bean name="Hellofrom" type="cn.com.mylu.Hellofrom">
          ??? </form-bean>


          頁面hello.do----->?action元素的path屬性?------>?action元素的type屬性----->Hello.java---->Hello.java中的execute方法
          posted @ 2006-12-06 16:25 Super·shen BLOG 閱讀(351) | 評(píng)論 (0)編輯 收藏

          在講外連接之前,先舉例介紹內(nèi)連接,也就是一般的相等連接。
          select * from a, b where a.id = b.id;
          對(duì)于外連接,Oracle中可以使用“(+)”來表示,9i可以使用LEFT/RIGHT/FULL OUTER JOIN,下面將配合實(shí)例一一介紹。
          1. LEFT OUTER JOIN:左外關(guān)聯(lián)

          SELECT e.last_name, e.department_id, d.department_name?
          FROM employees e?
          LEFT OUTER JOIN departments d?
          ON (e.department_id = d.department_id);
          ?

          等價(jià)于
          SELECT e.last_name, e.department_id, d.department_name?
          FROM employees e, departments d?
          WHERE e.department_id=d.department_id(+);
          ?

          結(jié)果為:所有員工及對(duì)應(yīng)部門的記錄,包括沒有對(duì)應(yīng)部門編號(hào)department_id的員工記錄。
          2. RIGHT OUTER JOIN:右外關(guān)聯(lián)
          SELECT e.last_name, e.department_id, d.department_name?
          FROM employees e?
          RIGHT OUTER JOIN departments d?
          ON (e.department_id = d.department_id);
          ?

          等價(jià)于
          SELECT e.last_name, e.department_id, d.department_name?
          FROM employees e, departments d?
          WHERE e.department_id(+)=d.department_id;
          ?

          結(jié)果為:所有員工及對(duì)應(yīng)部門的記錄,包括沒有任何員工的部門記錄。
          3. FULL OUTER JOIN:全外關(guān)聯(lián)
          SELECT e.last_name, e.department_id, d.department_name?
          FROM employees e?
          FULL OUTER JOIN departments d?
          ON (e.department_id = d.department_id);
          ?

          結(jié)果為:所有員工及對(duì)應(yīng)部門的記錄,包括沒有對(duì)應(yīng)部門編號(hào)department_id的員工記錄和沒有任何員工的部門記錄。

          posted @ 2006-11-29 14:32 Super·shen BLOG 閱讀(413) | 評(píng)論 (0)編輯 收藏

          下棋沒啥長進(jìn),今天用了半個(gè)小時(shí)看看兵書,總結(jié)一下。

          開局基本原理:
          [盡快集結(jié)子力]
          [爭奪河界]

          1。 盡快集結(jié)子力

          ·????????如無必要,不要重復(fù)走同一子

          ·? ?? ???先出炮、馬 ,然后車、兵?? ?[車要通 馬要靈 炮要能呼應(yīng)]

          ·? ?? ???不可用一兩個(gè)棋盲目進(jìn)攻

          ·? ?? ???子力要互相呼應(yīng),互相配合,不可互相干擾和阻塞

          ·? ?? ???若吃兵使用對(duì)方能力快速出子或發(fā)動(dòng)攻勢(shì),便不要吃

          ·? ?? ???若吃兵使用對(duì)方能力快速出子或發(fā)動(dòng)攻勢(shì),便不要吃


          2.?????? 爭奪河界 :

          除車以外,其他棋子在河界附近都可發(fā)揮最大威力及控制力,在中心的棋子要調(diào)動(dòng)到兩翼也較靈活、快速,所以河界附近為兵家必爭之地。若河界附近被對(duì)方占領(lǐng),便得設(shè)法攻下它。反之,自己占據(jù)時(shí),須要堅(jiān)守并利用它向?qū)Ψ降木艑m進(jìn)攻。

          中局原理

          3.? ?? ? 善用「車」:

          4.????????在防守中進(jìn)攻,兼顧協(xié)調(diào)

          5.?????? 保護(hù)「士兵」:



          關(guān)鍵還是實(shí)戰(zhàn)時(shí)眼光銳利,先人一步。

          posted @ 2006-11-21 17:35 Super·shen BLOG 閱讀(5839) | 評(píng)論 (2)編輯 收藏
          String strsql = "select temp.*,rownum? from (select * from tb_awardinfo order by award_id desc )temp where rownum <=5";
          //自己亂寫的,不知道效率怎么樣,那位達(dá)人幫貼過代碼來參考參考
          posted @ 2006-11-21 16:17 Super·shen BLOG 閱讀(849) | 評(píng)論 (0)編輯 收藏

          oracle 分頁

          1. 最好還是利用分析函數(shù)
          row_number() over ( partition by col1 order by col2 )

          比如想取出100-150條記錄,按照tname排序

          select tname,tabtype from (
          ?? select tname,tabtype,row_number() over ( order by tname ) rn from tab
          )
          where rn between 100 and 150;

          2. 直接使用rownum 虛列
          select tname,tabtype from (
          ?? select tname,tabtype,rownum rn from tab where rownum <= 150
          )
          where rn >= 100;
          使用序列不能基于整個(gè)記錄集合進(jìn)行排序,如果指定了order by子句,排序的的是選出來的記錄集的排序.

          ------------------------------------------------------------------------
          經(jīng)過測(cè)試,在100萬條數(shù)據(jù)的表中,檢索數(shù)據(jù)的時(shí)候,方法2的速度要比方法1要快的.


          排序分頁

          說明:Oracle下用rownum進(jìn)行分頁時(shí) 很容易出現(xiàn)排序的錯(cuò)亂。


          但多套一層select 就能很好的解決該問題,特此記錄,語句如下:

          select t2.* from (select t1.*, rownum rn from (select * from tb_courseinfo order by rownum? desc )t1 where rownum <=?150 )t2 where rn >100


          不懂具體效率怎么樣,和上邊一樣應(yīng)該還可以。




          實(shí)際例子代碼如下

          int curpage=1;//當(dāng)前頁
          int page_record=20;//每頁顯示的記錄數(shù)
          int introwcount=0; // 記錄數(shù)
          if(request.getParameter("page")==null||Integer.parseInt(request.getParameter("page"))<=0)
          {
          curpage = 0;
          }
          else
          {
          curpage=Integer.parseInt(request.getParameter("page"))-1;//獲取傳遞的值,需要顯示的頁
          }

          String sql = "select t2.* from (select t1.*, rownum rn from (select * from tb_courseinfo order by rownum? desc )t1 where rownum <= "+(curpage+1)*page_record+" )t2 where rn > "+curpage*page_record;



          posted @ 2006-11-21 16:11 Super·shen BLOG 閱讀(4136) | 評(píng)論 (3)編輯 收藏
          主站蜘蛛池模板: 大连市| 沈丘县| 高安市| 云南省| 灌云县| 潍坊市| 正宁县| 元江| 香格里拉县| 清流县| 咸丰县| 胶南市| 寿宁县| 昌乐县| 屯门区| 桃源县| 营山县| 平乡县| 雷波县| 斗六市| 炎陵县| 乐东| 宣恩县| 盈江县| 福海县| 阿拉善右旗| 扎兰屯市| 通许县| 沂水县| 盐池县| 伽师县| 温州市| 舞阳县| 安远县| 思茅市| 长顺县| 雷山县| 潼南县| 原阳县| 双辽市| 屏东县|