星期四, 3月 29, 2012

[Eclipse] 利用Eclipse建立Ant用的build.xml

本文說明如果用eclipse快速建立Ant的Build.xml檔

使用步驟:
1.在專案上按右鍵->Export

2.General->Ant Buildfiles


3. 選擇要匯出build.xml的專案


4.由於這個檔案是工具產生的,請依自已的需求做修改。

[Alfresco] How to create Java backed web script in alfresco (2)

痛過的經驗記錄一下。
看過上一篇的Java backed 架構圖之後,
得知我們需要完成四個Components,
分別是
1.XML descriptor document (Describing the web script)
2.Freemarker (Writing the response template-FTL)
3.Java class (Writing the web script controller)
4.Spring bean XML(Register the Java class in the Alfresco)

星期三, 3月 28, 2012

[jQuery plugin] Validator不透過 submit來觸發檢查欄位

今天遇到一個validator ui上的問題, 由於textbox加了combobox的plugin後,將它放入div裡包起來,會有異常的bug。 把原本驗證textbox拿到form的外面。 所以另外用一個元素來觸發驗證的動作!! 範例如下:


Triggers element validation programmatically.
 //because quota text box position is out of form
 $("#quota_input").change(function(){
  //do validation by changing value in the text box
  $("#filesizeForm").validate().element("#quotaType");
 });

[jQuery plugin] Images gallery

一些覺得不錯的Images gallery

jQuery masonry
http://masonry.desandro.com/demos/images.html

拍立得效果
http://www.microsoft.com/web/downloads/platform.aspx

[Java] 執行Shell script


想要使用java來執行Shell Script嗎?
透過Process就可以完成了,以下是tail指令的簡單範例,
記得reader要指定編碼,不然中文字會亂碼喔

Process processOnLinux = Runtime.getRuntime().exec("tail -500 " + USR_LOG);
reader = new BufferedInputStream(processOnLinux.getInputStream());
reader = new InputStreamReader(processOnLinux.getInputStream(), "UTF-8");

星期六, 3月 24, 2012

[SVN] VisualSVN

懶的了解SVN安裝繁雜的步驟的朋友(或跟我一樣裝了一直爆炸XD),
先直接安裝VisualSVN吧,完全無腦安全,省時省力:)

其他常用的功能:
將專案匯入資源庫(import project to VisualSVN) 參考這裡

weiteki-MacBook-Air:workspace ibigd$> svn import -m 'import message' your_project_name https://163.17.83.13/svn/your_repository/trunk/your_project_name


星期四, 3月 22, 2012

[Java] XProperties

如果你的Properties含有變數串接變數的話,
例如:
IP=192.168.0.1
URL=http:/{IP}/WebServer
可以使用這個擴展的XProperties


星期日, 3月 18, 2012

[TOMCAT] MAC OSX 安裝TOMCAT 7.0.x

平常在公司都是用WINDOWS的Eclipse開發JAVA,
希望在AIR也把環境設定,
這樣就不需要把公司的電腦(超重XD)常常帶來帶去。

安裝流程(參考這篇)

[SVN] Windows 安裝 SVN

今天試了很多SVN版本終於有RUN一個正常的組合XD
提供給有需要的人參考

OS:Windows 7
Appserv:appserv-win32-2.5.10.exe
Subversion:1.4.6

目前搭1.7.3~1.7.4這二個版本在設定完httpd.conf後,重啟Apach都會有無法執行
mod_dav_svn.so和mod_authz_svn.so這二個modules的錯誤。


 一、SVN安裝流程:



1.安裝Appserv 2.5.10
2.安裝SVN 1.4.6
3.Apache的httpd.conf設定

星期四, 3月 15, 2012

[Java] Jersey 清除 response cache

通常在IE瀏覽器常常會遇到亂Cache一通的問題,
Jersey提供Response物件來讓我們簡單的可以清除Cache。
好好利用cache也是一個節省頻寬跟效能的好方法。
如果有很多方法都需要清Cache的話,就考慮使用Filter的寫法比較方便。

@GET
 @Path("/{uid}")
 @Produces(MediaType.APPLICATION_JSON)
public Response getUser(
   @PathParam(value="uid") String uid){

//do sth

ResponseBuilder rb = Response.ok(respJSON.toString());
  CacheControl cc = new CacheControl();
     cc.setNoCache(true); 
     return rb.cacheControl(cc).build();

}

[Java] 實作Filter

Filter顧名思義就是過濾器,在JSP/Servlet中,Filter的功用就是在擔任Request與Response的過濾功能,當使用者的request發出至某資源時,您可以先對request作一些前置處理,例如進行身份驗證、過濾不安全的請求、監視統計請求的來源與出處等等,Filter的功能是雙向的,您也可以對JSP/Servlet的response進行過濾或進行某些處理,例如對輸出先進行壓縮、對XML的呈現進行轉換等等。

總而言之,Filter可以擔任瀏覽器與JSP/Servlet之間的一個中介處理者,一些request的前置處理動作又一些response的後置處理,都可以交由這個中介處理者來完成,當然Filter可以達到的功能,我們也可以直接撰寫在JSP/Servlet中,但如果有很多JSP/Servlet都需要相同的處理,例如某些網頁都需要統一的身份驗證方式時,與其在每一個網頁中都撰寫驗證的程式碼,我們不如直接撰寫Filter,讓它來統一進行處理。

最近在測試Web Cache的行為,發現寫在Filter裡面的header最後能在回應標頭看到你所設定的結果。 如果在一般JSP的頁面加上Meta的Tags或使用response.setHeader的方式,在回應標頭都無法看到你所設定的結果。 但二者的快取效果都是一樣的。

@Override
 public void doFilter(
   ServletRequest request, 
   ServletResponse response,
   FilterChain chain) throws IOException, ServletException {
  
  //HttpServletRequest hsresq = (HttpServletRequest) request;
  HttpServletResponse hsresp = (HttpServletResponse)response;
  
  //current request server url(Don't include host and sitename)
  //String currentURL = hsresq.getServletPath();
  hsresp.setHeader("Pragma","no-cache"); 
  hsresp.setHeader("Cache-Control","no-cache,no-store,must-revalidate"); 
  //prevents caching at the proxy server
  hsresp.setDateHeader("Expires", 0); 
  
  chain.doFilter(request, response);
 }

在web.xml設定只對jsp的頁面進行filter,
注意url-pattern設定成/*.jsp是錯誤的。

<filter>
  <filter-name>JSPNoCacheFilter</filter-name>
  <filter-class>filter.JSPNoCacheFilter</filter-class>
 </filter>
    <filter-mapping>
 <filter-name>JSPNoCacheFilter</filter-name>
     <url-pattern>*.jsp</url-pattern>
 </filter-mapping>
Reference:
JSP Servlet Filter-1

星期二, 3月 13, 2012

Web Cache Issue

簡單記綠一下看完一些Web Cache資料的心得,
方便以後快速學習。

使用Cache的理由

To reduce latency
To reduce network traffic

Web Caches的種類
Browser Caches:
Proxy Caches:
Gateway Caches: 如Content delivery networks (CDNs)

在你的網頁控制Caches


在網頁的Header加上HTML Meta Tags
PRAGMA HTTP HEADERS:
<meta http-equiv="Pragma" content="no-cache">

星期日, 3月 11, 2012

[Java] Jersey WADL

當Jerey愈用愈久之後,
如何產生這些URL資源的描述文件就是一件苦惱的事,
有需求的人可以參考這篇文章 Jersey and WADL(Web Application Description Language)
假設你已經有一個jersey的站台之後並完成WADL相關組態設定之後,
就可以呼叫http://localhost:9998/application.wadl來取得你的Restful應用程式的WADL


    
    
        
            
                
                    
                
            
        
    




要建立WADL可以參考以下二種方法

How to configure your webapp to provide extended WADL
This page describes what's necessary for getting an extended WADL generated within your running webapp.

How to generate extended WADL (without a webapp)
The generate-wadl sample shows how to generate (extended) WADL with maven(project management tool), without the need to start the webapp. This sample also has a README you might want to look at.

星期六, 3月 10, 2012

[Asp.net] 佈署.net framework 4.0發生錯誤

今天在IIS佈署新的Asp.net 4.0 site,
常常會發生Server unavaliable和伺服器應用程式無法使用這二個錯誤,
查到保哥這篇的實用教學ASP.NET 4.0 安裝在 IIS6 最常遇到的四個問題
原來造成錯誤的原因在於原本的IIS裡面已經有了其他.net framework 2.0的站台,
由於原來的2.0站台已經使用了DefaultAppPool,但新設的4.0站台預設也是使用DefaultAppPool,會導致先被執行的網站會搶到執行權,導致其他站台產生上述的錯誤。

保哥提供二種解法:
一:設定應用程式集區:
設定方法可以參考這篇文章:設定應用程式集區(AppPool)防止Server上的Web應用程式彼此干擾

二:將所有站台全部設成.net.framework 4.0

當然選擇第一個方法設定新的應用程式集區是最好的。比較不會費力。

星期四, 3月 08, 2012

[Alfresco] 模擬上傳大頭照發生錯誤


11:24:45,307  ERROR [node.integrity.IntegrityChecker] Found 1 integrity violations:
Invalid property value:
   Node: workspace://SpacesStore/f07b92c9-e188-4991-b55d-eef404d60eda
   Type: {http://www.alfresco.org/model/content/1.0}content
   Property: {http://www.alfresco.org/model/content/1.0}name
   Constraint: 02090038 Value '?????????????????????.png' is not valid as a file name.
This property must be a valid file name.

很明顯又是中文亂碼的問題,查了一下就是在Multipart/data-form的時候,
使用getbytes的方法時,未指定utf-8編碼,導致抓的預設編碼跟自已的VM環境不一致而產生的錯誤。

星期一, 3月 05, 2012

[Java] 在JDBC使用SQL IN

這篇文章Batching Select Statements in JDBC提供四種解法

擷錄前言:


In networking, one of the most expensive things you can do is make a server roundtrip. In JDBC, this corresponds to a database call. If you are doing inserts, updates or deletes, you can use the executeBatch() signature to cut down the number of trips to the server. Unfortunately, there is no such built-in mechanism for select queries.

Suppose you want to get the names for a given list of ids. Logically, we would want to do something like:

PreparedStatement stmt = conn.prepareStatement(
 "select id, name from users where id in (?)");
stmt.setString("1,2,3");
However, this will not work. JDBC only allows you to substitute a single literal value in the "?". You can't substitute things that are meant to become part of the SQL statement. This is necessary because if the SQL itself can change, the driver can't precompile the statement. It also has the nice side effect of preventing SQL injection attacks. Instead, you have four options for the implementation:
  1. Run the query separately for each id
  2. Build one query to do everything
  3. Use a stored procedure
  4. Select batching
最後選擇效能最快的一種。但尚未測試時間差多少倍。
StringBuilder inClause = new StringBuilder();
boolean firstValue = true;
for (int i=0; i < batchSize; i++) {
  inClause.append('?');
  if ( firstValue ) {
    firstValue = false;
  } else {
    inClause.append(',');
  }
}
PreparedStatement stmt = conn.prepareStatement(
    "select id, name from users where id in (" + inClause.toString() + ')');


for (int i=0; i < batchSize; i++) {
  stmt.setInt(i);  // or whatever values you are trying to query by
}


星期四, 3月 01, 2012

[jQuery plugin] 設定Cursor在Textbox的位置

最近在實作自動將Textbox前後空白字元清除的功能時,
遇到將tirm完的新字串重設回Textbox時,
Cursor的位置無法停留至文字的最後位置
網路上的範例也蠻多的,以下範例是改自參考的網址測試
IE 8,IE 9,Chrome,FF可正常運作。
有其他需求的話可參考jQuery的caret plugin

其他你感興趣的文章

Related Posts with Thumbnails