Author Archives: vincent

網站歸入錯誤的 Websense 分類

最近發現網站被 Websense 列在 ‘Possible Damaged Content’ 分類, Websense 是廣泛為大型企業採用的資安設備, 員工連網時 Websense 會比對資料庫, 如果網站列在可能有威脅或是違反公司政策的分類, 員工就無法瀏覽這個網站。

這時候只要參考這個 網址, 寫 email 向 Websense 反應, 大約 2 個工作天 Websense 就會把你反應的網站改列到正確的分類, 大約再 1~2 天 Websense 設備的資料庫會更新完畢, 這時候網站最不會被 Websense 擋掉了。

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Struts2 + JSON plugin

簡單記錄 struts2 + json plugin 的 AJAX 寫法

1. 在 struts2 的 xml 檔加入以下 json 設定

<package name=”json” namespace=”/json” extends=”json-default”>
<action name=”getCustomer” class=”com.amjet.web.action.JsonAction” method=”getCustomer”>
<result name=”success” type=”json”>
<param name=”root”>response</param>
</result>
</action>
</package>

2. json action 內放一個 property response, 例如

private Map<String,Object> response;

加上 getter, setter, 回傳 ajax response

3. json action method

public String getCustomer() {

response=new HashMap<String,Object>();

response.put(“info”,<customer info>);
return SUCCESS;
}

4. 頁面接取 json 資料

function doQuery() {
$.ajax({
url: ‘<s:url action=”getCustomer” namespace=”/json”/>’,
type: ‘POST’,
dataType: ‘json’,
data: { id_no: id_no },
success: function(data,status,xhr) {

***  your handler here ***

}
});
}

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

jQuery 處理 HTML table

簡單記錄 jQuery 逐 row 逐 cell 處理 HTML table 的兩個範例,首先是傳統的方法,HTML table 設定 id 為 dt

$(“#dt tr”).each(function () {
html+=”<tr>”;
$(this).find(“td”).each(function() {
html+=”<td>”+$(this).text()+”</td>”;
});
html+=”</tr>”;
});

另一個例子是處理相當受歡迎的 plugin datatables,同樣設定 id 為 dt

var rows=$(“#dt”).dataTable().fnGetNodes();
for(i=0;i<rows.length;i++) {
html+=”<tr>”;
$(rows[i]).find(“td”).each(function() {
if ( i == 0 ) {
html+=”<td>”+$(this).text()+”</td>”;
} else {
html+=”<td>”+$(this).text()+”</td>”;
}
});
html+=”</tr>”;
};

 

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Struts2 tips

當 struts2 的 action code 拋出 exception 時,有一個頁面提示系統的使用者是相當方便的,一方面讓使用者了解目前發生了異常的情形,也可以在頁面上置入錯誤碼讓問題回報及解決更加有效率。本文主要參考這個 網址

首先在 struts.xml 要有以下設定

<global-results>
<result name=”Exception”>/Exception.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception=”java.lang.Exception” result=”Exception”/>
</global-exception-mappings>

在 jsp 可以顯示 ‘目前系統發生異常狀況,錯誤代碼為 xxxxxx ,請向系統管理人員回報以便儘快處理’ 。

另外在 jsp 的 OGNL 語法字串比較部份有一個小提示

<s:if test=”%{#request.err_code.equals(‘A’)”>

這個寫法 err_code 是字串,’A’ 是一個 character,所以即使 action err_code 傳來 “A”,比對的結果仍然是 false

<s:if test=’%{#request.err_code.equals(“A”)’>

以上的寫法比對的結果才會是 true

 

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Spring framework transaction control (Programmatic)

在一些比較早期的專案可能 application server、framework、java runtime 的版本都比較舊或不允許做太大幅度的變動,這時候以程式來控制 transaction 變成唯一的選擇,本文主要參考這個 網址

首先在 applicationContext.xml 設定 transaction 相關物件

<bean id=”transactionManagerJDBC”
class=”org.springframework.jdbc.datasource.DataSourceTransactionManager”>
<property name=”dataSource” ref=”dataSource”></property>
</bean>

<bean id=”transactionTemplate” class=”org.springframework.transaction.support.TransactionTemplate”>
<property name=”transactionManager” ref=”transactionManagerJDBC”></property>
</bean>

<bean id=”jdbcTemplate” class=”org.springframework.jdbc.core.JdbcTemplate”>
<property name=”dataSource” ref=”dataSource”></property>
</bean>

接著將以上物件 inject 到需要 transaction contorl 的 java class,這部份就不再細述,transaction code example 如下

transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {

// do you works here
} catch (Exception e) {
status.setRollbackOnly();
}
}
});

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...