<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-40  評(píng)論-66  文章-0  trackbacks-0
      2008年2月26日
    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 閱讀(1795) | 評(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 閱讀(502) | 評(píng)論 (0)編輯 收藏

    普遍的,簡(jiǎn)單的權(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 閱讀(802) | 評(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 閱讀(1738) | 評(píng)論 (1)編輯 收藏

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

    posted @ 2008-02-28 14:19 Super·shen BLOG 閱讀(745) | 評(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 閱讀(1473) | 評(píng)論 (0)編輯 收藏
    我們來看看到底如何從POST表單收集數(shù)據(jù)到CGI程序,下面給出了一個(gè)比較簡(jiǎn)單的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ù)的字長(zhǎng),然后讀取相應(yīng)長(zhǎng)度的字符串。因?yàn)閿?shù)據(jù)內(nèi)容在傳輸?shù)倪^程中是經(jīng)過了編碼的,所以必須進(jìn)行相應(yīng)的解碼。編碼的規(guī)則很簡(jiǎn)單,主要的有這幾條:     

    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 閱讀(2771) | 評(píng)論 (1)編輯 收藏
    啥都不說,直接看代碼!

    簡(jiǎn)單輸出代碼

    #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 閱讀(747) | 評(píng)論 (0)編輯 收藏
    主站蜘蛛池模板: 国产成人精品男人免费| 美女视频黄的全免费视频| ssswww日本免费网站片| 成在线人免费无码高潮喷水| 免费国产成人18在线观看| 亚洲av无码乱码在线观看野外 | 日韩伦理片电影在线免费观看| 国产免费一区二区三区VR| 亚洲成人午夜电影| 久久午夜夜伦鲁鲁片免费无码| 免费国产综合视频在线看 | 国产亚洲精品激情都市| 亚洲特级aaaaaa毛片| 久久久久久久久久免免费精品 | 人人狠狠综合久久亚洲| 亚洲熟伦熟女新五十路熟妇| 亚洲精品无播放器在线播放 | 麻豆亚洲AV成人无码久久精品 | 色拍自拍亚洲综合图区| 一级毛片一级毛片免费毛片 | 全部免费a级毛片| 精品亚洲国产成人av| 欧洲美熟女乱又伦免费视频| 久久精品国产这里是免费| 国产在线观看免费完整版中文版 | 无码人妻一区二区三区免费视频| 亚洲aⅴ无码专区在线观看春色 | 国产伦精品一区二区三区免费下载| 亚洲男人第一av网站| 亚洲视频免费在线看| 久久成人免费电影| 中文字幕第13亚洲另类| 亚洲AV成人一区二区三区在线看| 亚洲成年人免费网站| 国产成人精品日本亚洲| 一级黄色免费网站| 国产亚洲精品成人AA片新蒲金| 亚洲一级在线观看| 国产在线播放免费| 亚洲一区二区三区在线观看网站| 免费看污成人午夜网站|