2013年6月4日 星期二

[HBase programming, IR, Java]檢索條件值的關係為AND 或者是OR (Boolean retrieval)

假設每個值之間以空白間隔

String qryKeywords = "竹筍 豆皮 好吃 開心";



Condition 1:
查詢條件之間以"和"關係存在( The terms in a query are linked together with AND)

ArrayList<Filter> filtersArrayList = new ArrayList<Filter>(); 
Filter filter = null;
String [] qryKeywordsList =qryKeywords.split("\\s+");


for (int i=0; i< qryKeywordsList.length; i++){

if (!qryKeywordsList[i].equals("")){
filter= new ValueFilter(CompareFilter.CompareOp.EQUAL,new SubstringComparator(qryKeywordsList[i]));    
filtersArrayList.add(filter);
}
}


Scan s =  new  Scan(); 
s.setFilter(filtersArrayList);  
ResultScanner rs = table.getScanner(s);  
while ((r = rs.next()) != null) {
for (KeyValue kv : r.list())  
                System.out.println( "row : " + new  String(kv.getRow()));  
                System.out.println( "column : " + new  String(kv.getColumn()));  
                System.out.println( "value : " + new  String(kv.getValue()));  
        }  
}  



Condition 2:
查詢條件之間以"或"關係存在(The terms in a query are linked together with OR)
==>利用RegexStringComparator


ArrayList<Filter> filtersArrayList = new ArrayList<Filter>(); 
Filter filter = null;
String qryKeywordsReg =qryKeywords.replaceAll("\\s+", "|");
filter= new ValueFilter(CompareFilter.CompareOp.EQUAL,new RegexStringComparator(qryKeywordsReg));    
filtersArrayList.add(filter);


Scan s =  new  Scan(); 
s.setFilter(filtersArrayList);  
ResultScanner rs = table.getScanner(s);  
while ((r = rs.next()) != null) {
for (KeyValue kv : r.list())  
                System.out.println( "row key : " + new  String(kv.getRow()));  
                System.out.println( "column : " + new  String(kv.getColumn()));  
                System.out.println( "value : " + new  String(kv.getValue()));  
        }  
}  





2013年5月3日 星期五

[Java Servlet]網址的參數有空白(Spaces in URL)


更改該參數值的編碼
利用URLEncoder和URLDecoder

For example,

import java.net.URLEncoder;
import java.net.URLDecoder;


Sent:

PrintWriter out = null;
out = response.getWriter();

out.print("<a href=");
out.print("Query?qryKeywords=" + URLEncoder.encode(qryKeywords, "UTF-8"));
out.println(">" + qryKeywords + "</a>");

---
receive接收可能有空白鍵值網址的程式碼:



protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

...
       URLDecoder.decode(request.getParameter("qryKeywords"), "UTF-8")


..
}

2013年4月27日 星期六

[tomcat] server.xml設定, UTF8, 限定IP存取,自動佈署(server.xml setting for utf8, IP access, auto deployment)


tomcat/conf/server.xml

<!--get-傳送時為utf8->
<Connector port="8080"  URIEncoding="UTF-8"/>


<!--host下appBase是設定整個網站的根目錄->
     <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->


 <!-- IP Access SETTING,設定該網站允許和限制存取的ip, allow是設定可存取的ip,deny是設定拒絕存取的ip-->
        <Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="60.251.40.*||127.0.0.1" deny=""/>

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." resolveHosts="false" suffix=".txt"/>



<!--context下 path若不填任何值,該project就變成出現在網站根目錄了,所以path是設定虛擬目錄名稱, 每個content就是設定一個虛擬目錄-->
      <Context docBase="/opt/tomcat/webapps/proofmed" path="/proofmed" reloadable="true" source="org.eclipse.jst.jee.server:hospital.proofmed" />
    <Context docBase="/opt/tomcat/webapps/proofdrug" path="/proofdrug" reloadable="true" source="org.eclipse.jst.jee.server:hospital.proofdrug" />
</Host>

註解:在eclipse中修改server.xml
左側專案樹 (最下面)-> Servers -> TomcatXXXX-config : server.xml



2013年3月26日 星期二

[tomcat]一台電腦上多個tomcat服務(Multiple Tomcat Services in a Linux machine)

假設安裝兩個tomcat

編號 檔案放置目錄 欲設定的網站存取路徑
1 /usr/tomcat http://IP:8080/
2 /usr/tomcat2 http://IP:9080/

也就是直接tomcat解壓縮的檔案複製一份到tomcat2目錄


修改系統環境變量(vi etc/environment)

 JAVA_HOME="/usr/java/jdk1.6.0_38"  (JDK檔案放置目錄)
CATALINA_HOME="/usr/tomcat"  (tomcat檔案放置目錄)
CATALINA_HOME2="/usr/tomcat2"  (tomcat2檔案放置目錄)

CATALINA_BASE="/usr/tomcat"(tomcat1目錄)
CATALINA_BASE2="/usr/tomcat2"(tomcat2目錄)


修改tomcat2目錄下bin/

修改tomcat2/bin/catalina.sh  (vi tomcat2/bin/catalina.sh)
把CATALINA_HOME全部替換成CATALINA_HOME2
 (按esc鍵, vi指令為:1,$s/CATALINA_HOME/CATALINA_HOME2/g);
 CATALINA_BASE換成CATALINA_BASE2
(按esc鍵, vi指令為:1,$s/CATALINA_BASE/CATALINA_BASE2/g)



修改tomcat2目錄下conf/server.xml文件(vi opt/tomcat2/conf/server.xml)


  • <Server port="9005" shutdown="SHUTDOWN">  預設port="8005"
  • <Connector port="9080" protocol="HTTP/1.1"   connectionTimeout="20000"            redirectPort="8443" URIEncoding="UTF-8" /> 預設port="8080"
  • <Connector port="9009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/> 預設port="8009"

重開機後,個別重新啟動
./usr/tomcat/bin/startup.sh
./usr/tomcat2/bin/startup.sh

就可以看到成果


2013年3月21日 星期四

[jQuery]jQuery Image zoom plugin ( jQuery.elevatezoom.js圖片放大縮小)

網址

http://www.elevateweb.co.uk/image-zoom

說明

如果要更改放大圖片的浮動視窗出現位置、放大鏡的形狀、範圍和放大倍數、遮罩顏色...等
可依據demo 的example上顯示的參數說明去調整

如果看不到放大靜的框框,請更改浮動視窗的<div>的z-index為更小的數字,例如:0

2013年3月20日 星期三

[Eclipse] [Tomcat] 安裝和設定Eclipse 部署Tomcat的plugin(Eclipse Tomcat Launcher plugin )

下載和設定  Download and set up
  1. download plugin from
     http://www.eclipsetotale.com/tomcatPlugin.html
    (Sysdeo Eclipse Tomcat Launcher plugin)
    Notice: version of tomcat and eclipse

  2. 解壓縮,放到eclipse的 \plugins or \dropins 目錄

  3. 重新啟動eclipse,看到工具列多了三隻小貓的icon,可各別啟動,暫停,重新啟動tomcat

環境設定
  1. eclipse-->windows-->preference-->tomcat -->

    tomcat version:根據下載使用的版本選擇
    tomcat home: 填選tomcat存放目錄
    Context declaration mode: Server.xml

  2. eclipse-->windows-->preference-->tomcat -->Advanced

    default setting and values

  3. eclipse-->windows-->preference-->tomcat -->JVM Settings

    選擇一JRE

  4. eclipse-->windows-->preference-->tomcat -->Source Path

    選擇Automatically compute source path

  5. eclipse-->windows-->preference-->tomcat -->Tomcat Manager App

    default setting and values


以後撰寫Java servlet or JSP程式時,只要透過三隻小貓icon啟動tomcat server或 [run] icon啟動tomcat server

參考文獻 Reference:
http://werdna1222coldcodes.blogspot.tw/2012/08/Sysdeo-Eclipse-Tomcat-Launcher-plugin.html

[jQuery] Nested UL with toggle event

Code:
<HTML><HEAD>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script>

$(document).ready(function(){
    $('ul', this).click(function(event) {
      $(this).children("ul").toggle("quick");
      event.stopPropagation();
    });
});
</script>
</HEAD>

<BODY bgcolor=#ffffff link='#ff0000' vlink='#0000ff'>

    <ul><a href="#">A</a>
            <ul><a href="#">1</a>
            <ul><a href="#">1.1</a></ul>
            <ul><a href="#">1.2</a></ul>
            </ul>
            <ul><a href="#">2</a>
            <ul><a href="#">2.1</a></ul>
            <ul><a href="#">2.2</a></ul>
            </ul>
    </ul>
    <ul><a href="#">B</a>
            <ul><a href="#">3</a></ul>
            <ul><a href="#">4</a></ul>
    </ul>
    <ul><a href="#">C</a>
            <ul><a href="#">5</a></ul>
            <ul><a href="#">6</a></ul>
    </ul>
</ul>
</BODY>
</HTML>

Demo: