
2008年3月1日
springside3背景struts2.1.2 spring2.5.6 Hibernate3.4GA
1.struts2
使用ZeroConfig + CodeBehind插件,實現約定大于配置的零配置文件風格.
根本不用配置struts.xml文件
這里就是action實現annotation CodeBehind。
如方法
通過 /user/user!input.action訪問, 并轉到 /user/user-xxx.jsp頁面
即namespace + action name + "-" + "xxx.jsp"
另外其中 action中需要注入的 service 使用annotation ,在set方法前 加入@request 或 @ autowired 或 @resource
注釋(具體是用那個暫時無法搞清楚,總之我用request 就不行,另外兩個都可以)
有了這個代碼之后 就能注入spring 環境中的 id = userManager 的bean (我個人理解)
而spring中 id = userManager 的bean 也是通過自動注入完成的
主要代碼是 applicationContext.xml文件中的
代碼:
2.spring
spring2.5.6的annotation特性用的比較泛濫。 新手剛開始看的一頭霧水很正常。
xml文件中配置自動注冊bean,通過掃描包中的帶注解的類。即這個代碼:
掃描到下面的類,就自動注冊成 id=userManager
3.hibernate
使用hiberante3 注解,不要XML配置,實體類注解不用多說。
需要注意的是entity類的掃描配置
看清楚是掃描包,不是掃描類! 所以實體類com.mylu.User是無法掃描到,要放在 com.mylu.xxx.User才能掃描到!
下邊按照ss3風格做的例子,去掉spring security 框架的, 結構更清晰。
下載:實例代碼
附:
類庫
posted @
2009-01-08 17:01 Super·shen BLOG 閱讀(1795) |
評論 (2) |
編輯 收藏
在jsp中,其實jsp就是servlet,jsp和servlet也都是一個class:
1 .request.getRealPath(),這個方法已經不推薦使用,在servlet后繼版本中將被取締。
2.getServletContext().getRealPath("/")這個方法比較好用,可以直接在servlet和jsp中使用。
3.request.getSession().getServletContext().getRealPath()也可以在jsp和servlet使用。
4.this.getClass().getClassLoader().getResource("").getPath(),這個方法可以在任意jsp,servlet,java文件中使用,因為不管是jsp,servlet其實都是java程序,都是一個class。所以它應該是一個通用的方法。
posted @
2008-09-17 14:55 Super·shen BLOG 閱讀(502) |
評論 (0) |
編輯 收藏
普遍的,簡單的權限系統要求:
1.系統所有資源定義 [資源表] ( 還可以分為更小的權限表,操作表,這里通叫資源表)
2.定義角色 [角色表]
3.給角色指定資源(一個角色可以管理多個資源) [角色-資源表]
4.定義用戶組 [用戶表]
5.給用戶組指定角色(一個用戶組可以擁有多種角色) [用戶組-角色表]
6.給用戶指定角色(一個用戶可以擁有多種角色,可以直接指定角色,也可以繼承用戶組的角色)[用戶-角色表]
查找權限時:
根據用戶ID[用戶-角色表]或用戶組ID[用戶組-角色表],查到所有角色ID,再[角色-資源表]找到所有角色下的所有資源。
此就是用戶擁有的資源。(資源一般為模塊,當然也可以分更細的定義為頁面,操作方法等)
此權限設計適合于模塊化訪問系統,如OA
當然很多系統因地而已,不可能完全滿足,按照自己系統需求設計是最合適的設計。
posted @
2008-08-18 16:17 Super·shen BLOG 閱讀(802) |
評論 (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"); //這里改了。要是按原先的,會提示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'}; //不能用指針!
//插入數據
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("插入數據成功!\n");
int nrow = 0, ncolumn = 0;
char **azResult; //二維數組存放結果
//查詢數據
/*
int sqlite3_get_table(sqlite3*, const char *sql,char***result , int *nrow , int *ncolumn ,char **errmsg );
result中是以數組的形式存放你所查詢的數據,首先是表名,再是數據。
nrow ,ncolumn分別為查詢語句返回的結果集的行數,列數,沒有查到結果時返回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 的內存空間
sqlite3_free_table( azResult );
sqlite3_close(db); //關閉數據庫
return 0;
}
請注意數據庫文件 test.db的訪問權限! 這里改成777!
posted @
2008-03-01 17:11 Super·shen BLOG 閱讀(1737) |
評論 (1) |
編輯 收藏