在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。所以它應該是一個通用的方法。
普遍的,簡單的權限系統要求:
1.系統所有資源定義 [資源表] ( 還可以分為更小的權限表,操作表,這里通叫資源表)
2.定義角色 [角色表]
3.給角色指定資源(一個角色可以管理多個資源) [角色-資源表]
4.定義用戶組 [用戶表]
5.給用戶組指定角色(一個用戶組可以擁有多種角色) [用戶組-角色表]
6.給用戶指定角色(一個用戶可以擁有多種角色,可以直接指定角色,也可以繼承用戶組的角色)[用戶-角色表]
查找權限時:
根據用戶ID[用戶-角色表]或用戶組ID[用戶組-角色表],查到所有角色ID,再[角色-資源表]找到所有角色下的所有資源。
此就是用戶擁有的資源。(資源一般為模塊,當然也可以分更細的定義為頁面,操作方法等)
\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
[轉自] http://webdn.trueself.cn/archives/107
◆ 使用strtok函數分割。
原型:char *strtok(char *s, char delim);
strtok在s中查找包含在delim中的字符并用NULL('\0')來替換,直到找遍整個字符串。
功能:分解字符串為一組字符串。s為要分解的字符串,delim為分隔符字符串。
說明:首次調用時,s指向要分解的字符串,之后再次調用要把s設成NULL。
strtok在s中查找包含在delim中的字符并用NULL('\0')來替換,直到找遍整個字符串。
返回值:從s開頭開始的一個個被分割的串。當沒有被分割的串時則返回NULL。
所有delim中包含的字符都會被濾掉,并將被濾掉的地方設為一處分割的節點。
使用例:
#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函數分割。
原型:extern char *strstr(char *haystack,char *needle);
用法:#include <string.h>
功能:從字符串haystack中尋找needle第一次出現的位置(不比較結束NULL)
說明:返回指向第一次出現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比較適合多個字符作分隔符的場合,而strstr適合用字符串作分隔符的場合。
我們來看看到底如何從POST表單收集數據到CGI程序,下面給出了一個比較簡單的C源代碼:
#include<stdio.h>
#include<stdlib.h>
#define MAXLEN 80
#define EXTRA 5
/* 4個字節留給字段的名字"data", 1個字節留給"=" */
#define MAXINPUT MAXLEN+EXTRA+2
/* 1個字節留給換行符,還有一個留給后面的NULL */
#define DATAFILE "../data/data.txt"
/* 要被添加數據的文件 */
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>表單提交錯誤");
else{
FILE *f;
fgets(input, len+1, stdin);
unencode(input+EXTRA, input+len, data);
f =fopen(DATAFILE, "a");
if(f == NULL)
printf("<P>對不起,意外錯誤,不能夠保存你的數據");
else
fputs(data, f);
fclose(f);
printf("<P>非常感謝,您的數據已經被保存<BR>%s",data);
}
return 0;
}
從本質上來看,程序先從CONTENT_LENGTH環境變量中得到數據的字長,然后讀取相應長度的字符串。因為數據內容在傳輸的過程中是經過了編碼的,所以必須進行相應的解碼。編碼的規則很簡單,主要的有這幾條:
1. 表單中每個每個字段用字段名后跟等號,再接上上這個字段的值來表示,每個字段之間的內容用&連結; 2. 所有的空格符號用加號代替,所以在編碼碼段中出現空格是非法的;
3. 特殊的字符比如標點符號,和一些有特定意義的字符如“+”,用百分號后跟其對應的ACSII碼值來表示。
例如:如果用戶輸入的是:
Hello there!
那么數據傳送到服務器的時候經過編碼,就變成了data=Hello+there%21 上面的unencode()函數就是用來把編碼后的數據進行解碼的。在解碼完成后,數據被添加到data.txt文件的尾部,并在瀏覽其中回顯出來。
把文件編譯完成后,把它改名為collect.cgi后放在CGI目錄中就可以被表單調用了。下面給出了其相應的表單:
<FORM ACTION="/cgi-bin/collect.cgi" METHOD="POST" >
<P>請輸入您的留言(最多80個字符):<BR>
<INPUT NAME="data" SIZE="60" MAXLENGTH="80" ><BR>
<INPUT TYPE="SUBMIT" VALUE="確定">
</FORM >
事實上,這個程序只能作為例子,是不能夠正式的使用的。它漏掉了很關鍵的一個問題:當有多個用戶同時像文件寫入數據是,肯定會有錯誤發生。而對于一個這樣的程序而言,文件被同時寫入的幾率是很大的。因此,在比較正式的留言版程序中,都需要做一些更多的考慮,比如加入一個信號量,或者是借助于一個鑰匙文件等。因為那只是編程的技巧問題,在這兒就不多說了。
#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>
/* 轉換函數聲明 */
int htoi(char *);
/* 主函數 */
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; //判斷是否有等于號。
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);
}
/* 轉換為小寫 */
int islower (int ch )
{
return (unsigned int) (ch - 'a') < 26u;
}
/* convert hex string to int 16進制轉換成10進制 */
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);
}
http://samhe.javaeye.com/blog/142416 DWR(Direct Web Remoting)是一個WEB遠程調用框架.利用這個框架可以讓AJAX開發變得很簡單.利用DWR可以在客戶端利用JavaScript直接調用服務端的Java方法并返回值給JavaScript就好像直接本地客戶端調用一樣(DWR根據Java類來動態生成JavaScrip代碼).它的最新版本DWR0.6添加許多特性如:支持Dom Trees的自動配置,支持Spring(JavaScript遠程調用spring bean),更好瀏覽器支持,還支持一個可選的commons-logging日記操作.
1. dwr - direct web remote
2. 推技術
3. http 長連接
4. Comet ---- HTTP長連接的“服務器推”技術
5. Jetty服務器 ---- Jetty 6 Web 服務器針對 AJAX、Comet 應用的特點進行了很多創新的改進,請參考文章“AJAX,Comet and Jetty”(請參見 參考資源)。
http://wiki.javascud.org/display/dwrcn/Home
http://wiki.springside.org.cn/display/springside/DWR
學習共進!
MyEclipse 5.5 開發 Struts 1.2 簡單登錄的入門視頻(有聲+源碼) 2007-09-19 01:50
視頻講解: Netbeans 5.5 配置顯示中文 JavaDoc
入門視頻: 使用 MyEclipse 開發 Swing 應用
河南話講解 MyEclipse + Tomcat Servlet 開發入門視頻
MyEclipse + JPA + Toplink 開發視頻: 開發并運行第一個 JPA 項目
MyEclipse + JBoss 開發視頻: 配置,開發并運行第一個 EJB 3 項目
JDBC 入門視頻: 配置 SQL Explorer 插件, ODBC 數據源, 建表, 用 JDBC 讀取數據庫
Tomcat 入門視頻: 下載, 運行, 第一個 HelloWorld
Eclipse 入門視頻: 下載, 運行, 第一個 HelloWorldJava 入門視頻: 下載, 安裝 JDK, 配置環境變量, HelloWorld
推薦給初學者的 Java 視頻
Netbeans 6.0 M10 開發 UML 項目的入門視頻
MyEclipse UML 入門視頻2 - 根據代碼反向工程生成 UML
MyEclipse + Tomcat 開發視頻: 下載,安裝,配置,開發并運行Web項目
小電影: 用 MyEclipse 開發 Spring + Struts + Hibernate 的總結與操作視頻(9分鐘)
小電影: 用 MyEclipse 開發 Spring + Struts 的總結與操作視頻(7分鐘)
用MyEclipse 4 分鐘開發Spring整合Hibernate應用的視頻
在 Linux 上配置并運行 Tomcat 服務器(入門整理)(視頻)
Java 初學者入門視頻: 下載 JDK 和 Netbeans
Hibernate 英文 PPT 及 MyEclipse 操作視頻整理
推薦一點 MyEclipse 的官方Spring,Hibernate入門視頻教程
Netbeans 5.5 + JPA + Hibernate 3 + Tomcat 實例有聲視頻
夏昕 <<Spring 開發指南入門>>1 分鐘上手教程視頻(不帶解說)
Java EE 5 入門 PPT 講解有聲視頻 - 第二部分
Java EE 5 入門 PPT 講解有聲視頻 - 第一部分
Java EE 5 入門視頻 - 在 JSF 中使用 JPA
視頻:使用 Netbeans 5.5可視化開發 JSF 的簡單注冊流程
Java EE 5 入門視頻 - 在 J2SE 中使用 JPA
Weblogic 9 之旅圖文視頻 2 - Portal 開發環境設置, 簡單的Portal 開發(視頻已貼上)
用 JProfiler4 調優 Weblogic 和 Tomcat 的視頻(原創)
來自 http://www.aygfsteel.com/beansoft
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();
}
}
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 );
}
已經很久沒摸過FLASH了,由于要接一個項目需要用的flash實現。 當我使用flash cs3 寫程序時發現已經和以前的大不一樣了!多年沒接觸本來還想在友人面前顯耀一下寶刀未老,天哪,好多地方不一樣了,剛接觸還真不習慣,還出丑了。
flash cs3 的改變源自于 as3的重大改變。更源于flash player AM2的重大改變。
下邊的所有都是自己對JAVA的理解不知道對不對,有待于以后實踐驗證
用JAVA編程,無論是什么框架,什么庫,什么插件, 他們的也還是來自 最基本java類編程。
比如,我猜想 TOMCAT服務器,也是由一個帶MAIN方法的類來啟動的, 然后開通一個端口服務器,它的原理應該和java socket server編程應該是一個道理。主要是啟動一些類,來接受客戶端的請求(容器的原理應該是這樣吧)
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 程序中文顯示處理實例
3。1
<%@ page pageEncoding="ISO-8859-1"%>和<%@ page pageEncoding="GB2312"%>和<%@ page
pageEncoding="UTF-8"%>各自的意思是什么,他們是否只對post提交有效!
request.setCharacterEncoding("UTF-8")是什么意思?有什么區別?還有
response.setCharacterEncoding("UTF-8"),優先于下邊
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
setCharacterEncoding()該函數用來設置http請求或者相應的編碼。
對于request,是指提交內容的編碼,指定后可以通過getParameter()則直接獲得正確的字符串,如果不
指定,則默認使用iso8859-1編碼,需要進一步處理。參見下述"表單輸入"。值得注意的是在執行
setCharacterEncoding()之前,不能執行任何getParameter()。java doc上說明:This method must be
called prior to reading request parameters or reading input using getReader()。而且,該指定
只對POST方法有效,對GET方法無效。分析原因,應該是在執行第一個getParameter()的時候,java將會
按照編碼分析所有的提交內容,而后續的getParameter()不再進行分析,所以setCharacterEncoding()無
效。而對于GET方法提交表單是,提交的內容在URL中,一開始就已經按照編碼分析所有的提交內容,
setCharacterEncoding()自然就無效。
對于response,則是指定輸出內容的編碼,同時,該設置會傳遞給瀏覽器,告訴瀏覽器輸出內容所采用的
編碼。
3.2. jsp輸出
指定文件輸出到browser是使用的編碼,該設置也應該置于文件的開頭。例如:<%@ page
contentType="text/html; charset= GBK" %>。該設置和response.setCharacterEncoding("GBK")等效。
4。java EE程序利用過濾器 處理中文問實例
提交數據的編碼格式
tomcat默認提交格式是ISO-8859-1
可以通過設置過濾器(只針對post提交)或修改server.xml 的URIencoding 編碼格式(只針對get提交)
達到你想要的 數據提交編碼格式。
總結
---by mylu 18:26 2007-5-20
ORM
Object Relation Mapping
對象 關系 映射
對象 指實體域對象
關系 關系數據
模型
概念模型(實體-屬性)
關系數據模型(關系數據庫)
域模型(對象)
軟件分層
v - 表述層
c /
??? /業務層
m- 持久層(hibernate 技術實現)
??? \數據層
mvc 對應 各層次
概念實體關系
1對1
1對多
多對多
表與表之間的關系 參照完整性
外鍵
多對多
多對一
域對象之間的 關系
關聯 (一對一 一對多 多對多)
依賴 (一個類需要訪問另外一個類)
聚集 (一個類的對象是另一個類的一部分, 人和手)
一般化 (繼承關系)
域對象
?實體域對象? (實體EJB,POJO)
過程域對象? (會話EJB,消息驅動EJB,POJO)
事件域對象? ()
在hibernate中 一般只關注 實體域對象 和 過程域對象
域對象的關系
?域對象的關聯關系 是有方向的
體現在類的編碼不一樣的
單向關聯
雙向關聯
?
域對象的持久化
把對象從內存中 保存到持久化設備中去
ORM 與? ORM模式
ORM模式是一種持久化技術,還有其他模式的持久化技術。如主動域模式(BMP),JDO模式,CMP模式。
域模型和數據模型的各個不匹配之處
1,繼承
2,多對多
3,雙向
4。粒度
盡量少連接查詢,很消耗時間的操作
?
創建持久化類
1。持久化類符合javabean的規范,包含一些屬性 以及對應的getxxx 色天下學習方法
2。持久化類有一個id屬性,用來唯一表示類的每一個對象。 也叫OID 對象表示符
3。Hibernate要求持久化類必須提供一個不帶參數的默認構造方法
創建數據庫schema
創建對象-關系映射文件
(一般在eslispe中先創建數據庫 然后再創建持久化類以及映射文件)
hibernate 映射類型
hibernate的初始化
static{
try{
//根據默認位置的hibernate配置文件創建 configuration實例
Configuration config = new Configuration();
config.addClass(Customer.class);
//創建SessionFactory 實例
sessionFactory = config.buildSessinoFactroy();
}catch(Exception e){e.printStackTrace();}
}
SessionFactory 接口
一個SessionFactory 實例是對應一個數據源的,應用從SessionFactory 獲取session實例對象
1線程安全的
2重量級的,不能隨意創建和銷毀她的實例。
Session 接口
1 Session接口是hibernate應用最為廣泛的接口。
2 Session也被稱為持久化管理器,它提供和持久化相關的操作
3 Session有以下特點
?a 不是線程安全的 所以應避免多線程共用一個Session實例
?b Session實例是輕量級的,所謂輕量級是指他的創建和銷毀不需要消耗太多的資源。意味著程序中可以經常創建和銷毀Session實例,保證不多線程使用Session對象。
Session接口的常用方法:
save()
update()
delete()
load()
Session執行事務流程
Session session = factory.openSession();
Transaction tx;
try{
tx = session.beginTranscation();
//執行事務
...
//提交事務
tx.commit();
}
catche(Exception e)
{//如果出現異常,撤消事務
if(tx!=null)tx.rollback();
throw e;
}
finally{
session.close(); //不管事務是否成功,最后都要關閉session對象
}
}
?
?
?
?
版本0.1.0
(更新中...)
Table of Contents
Q: 如何使用導出功能
A: 為了使用導出功能,只需要在web.xml文件中加入eXtremeComponents的導出過濾器的配置,內容如下:
<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>
Q: 傳入中文參數亂碼,如下頁面:
<form id="form1" name="form1" method="post" action="應用eXtremeTable的action或是結果頁面名">
<select name="selecttype" size="6">
<option value="第一個">第一個</option>
<option value="第二個">第二個</option>
<option value="第三個">第三個</option>
</select>
<input type="text" name="username" />
<input type="submit" name="Submit" value="提交" />
</form>
當你提交時含有eXtremeTable的結果頁面會自動取得頁面上的表單參數,那怕是經過了action的mapping.findForward("forward"),在我的試用過程中到頁面上會出現傳遞過去的參數,但出現了亂碼問題,使用查詢(filter)功能是的中文參數問題類似。
A:
確認服務器的參數是否設置了正確的編碼,如果使用Tomcat請確認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" />
添加編碼過濾器到你的應用工程:
/*
* 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);
}
}
在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>
Q:導出時文件內容亂碼
A:首先請確認使用的是extremecomponents-1.0.1-M5-A4版以后的版本
Q:當變量名為"action",在IE下執行產生javascript錯誤
A: 內部使用了一些關鍵字,就目前我所知的為"action"、"submit"。建議大家命名時盡量避免,如果大家必須使用,則可以使用table標簽的autoIncludeParameters參數設置為"false":
autoIncludeParameters="false"
Q:怎么樣格式化輸出表單中的數據
A: 你可以設置列的cell:
詳細信息請參考指南
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>