2017年6月26日 星期一

Java 與 JSP 中文字形


Reference https://crluo0929.wordpress.com/

JSP 中文編碼問題

首先要先區別一下兩個術語的意義:
contentType : 指定的是 JSP 頁最終 Browser(客戶端) 所見到的網頁內容的編碼
就是瀏覽器上的的 encoding. 例如  JSPtw Forum 用的 contentType 就是  Big5
pageEncoding :  指定JSP 編寫時所用的編碼
這裡指的是在寫 JSP 時,是用什麼樣的編碼在撰寫,通常是 Big5 ,不過許多編輯器在存檔時也可以選擇檔案編碼。
JSP 在 compile 成 .class 時,會經過兩次的編碼,先是經過 pageEncoding 然後再來是轉成 UTF-8 的 java source code ,
最後跑出來的網頁用的是 contentType 。
所以若是 pageEncoding 選錯了,或沒設定( 預設 ISO8859-1 ) ,那在第一次編碼時中文就已經變亂碼了。
在 complie 成 bytecode 時,不管之前是用什麼編碼寫,在這個階段轉成的 java source code 都一定是 UTF-8 的編碼,
JAVAC 用 utf-8 的 ENCODING 讀取AVA原碼,編譯成字串是 utf-8 ENCODING 的 bytecode (.class)。
接著 Container 載入和執行 bytecode ,將執行結果傳給瀏覽器,而瀏覽器根據前面定義的 contentType 編碼讀顯示結果。
response 設定 ContentType 為 UTF-8 編碼
response.setContentType(“text/html; charset=utf-8″);
看到的 JSP 就是
<%@ page session="false" pageEncoding="big5″ contentType="text/html; charset=utf-8″ %>
也就是說,使用如上面這樣宣告 charset 為 UTF-8 編碼時,所有的字都會被編譯成 UTF-8 然後再轉換成 bytecode ,
若在這個頁面會送出 request 時,原本中文的參數也會被編譯成 UTF-8 送出,
因此在接收端的 jsp 也必須以 UTF-8 的方式編碼才能正常顯示。
接收端的 jsp 在接收參數時,因 Container 在傳遞參數時預設使用 ISO-8859-1 的方式,因此在接收端必須先以
ISO-8859-1 的方式解譯,然後再轉換成由傳送端傳過來的編碼 ( UTF-8 ) 。
如下面例子:
傳送端:
<%@ page language="java" contentType="text/html; charset=UTF-8″ %>
<a href="/Web/jsp/receive.jsp?name=小明>GET</a>
如此,傳送端會將 “小明" 以 UTF-8 編碼起來,並透過 Container 以 ISO-8859-1 的方式傳遞給接收端
接收端:
String name = request.getParameter( “name" ); //此時 name 為 ISO-8859-1
name = new String( name.getBytes( “8859_1″ ) ,  “UTF-8″ ) ;
上面這行轉換是因為傳送端把 “小明" 以 UTF-8 編碼,因此要以同樣的方式才能正常顯示
接收端另外一種寫法:
request.setCharacterEncoding( “UTF-8″ ) ; //預設會將所有參數的編碼方式由 ISO-8859-1 轉換成 UTF-8
String name = request.getParameter( “name" ); //此時,取到的 name 就已經是 UTF-8 編碼
再另外一種寫法:
如果在每個頁面都要加上 request.setCharacterEncoding() 這樣實在是不好維護,因此可以在 web.xml 裡加個 Filter ,
<filter>
<filter-name>encoding</filter-name>
<filter-class>MyFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>Big5</param-value>
</init-param>
</filter>
MyFilter 實作 Filter 在 init() 裡透過 FilterConfig 取得設定參數 Big5
在 doFilter 裡去設定 request.setCharacterEncoding( 取得的設定參數 ) 即可。
另外一種例子:
傳送端:
<%@ page language="java" contentType="text/html; charset=Big5″ %>
<a href="/Web/jsp/receive.jsp?name=小明&sex=<%= java.net.URLEncoder.encode( “男"  , “UTF-8″ ) %> >GET</a>
此時,在送出時, “小明" 會依據 charset 編碼被編譯成 Big5 ,但性別 “男"  會被指定以 UTF-8 編譯
接收端:
String name = request.getParameter( “name" ); //此時 name 為 ISO-8859-1
String sex = request.getParameter( “sex" ) ; //此時 sex 為 ISO-8859-1
name = new String( name.getBytes( “8859_1″ ) , “Big5″ ) ;
sex = new String( sex.getBytes( “8859_1″ ) , “UTF-8″ ) ;
因 name 在傳送端被編譯成 Big5 因此接收端須要以 Big5 轉譯才能正常顯示,
而 sex 在傳送端被 java.net.URLEncoder 指明要以 UTF-8 編碼,因此在接收端也必須以 UTF-8 轉譯才能正常顯示
若為此種例子,則無法使用
request.setCharacterEncoding( “Big5″ ) ;
因為若這樣使用,則接收端在接收參數時,所有的參數都會被以 Big5 轉譯,因此即使寫了
sex = new String( sex.getBytes( “8859_1″ ) , “UTF-8″ ) ;
此時的 sex.getBytes( “8859_1″ ) 的 sex 其實已經先被轉譯成 Big5 了,因此用 8859_1 轉譯出來就會是亂碼,
再轉換成 UTF-8 時,還是亂碼。
※ pageEncoding 和contentType的預設都是 ISO8859-1,而隨便設定了其中一個,另一個就跟著一樣 ( 不一定絕對 )。



ISO
SO 8859-1,正式編號為ISO/IEC 8859-1:1998,又稱Latin-1或「西歐語言」,是國際標準化組織ISO/IEC 8859的第一個8位字符集。它以ASCII為基礎,在空置的0xA0-0xFF的範圍內,加入96個字母符號,藉以供使用附加符號拉丁字母語言使用。曾推出過 ISO 8859-1:1987 版。
英語雖然沒有重音字母,但仍會標明為ISO/IEC 8859-1編碼。除此之外,歐洲以外的部分語言,如南非荷蘭語斯瓦希里語印尼語馬來語、菲律賓他加洛語等也可使用ISO/IEC 8859-1編碼。

2017年6月20日 星期二

open java jnlp





Select the Java folder, (If you do not see Java, go back up one level to the c:/ drive and select Program Files(x86), then select the Java folder. If you do not have a Java folder here, you will want to go to www.java.com and download the latest version before continuing with these steps.)
Double click the latest jre folder (example: jre7, jre1.8_25, etc)
Double click the bin folder Double
click the javaws application Click the Close button JNLP files will now open, by default, with Java Web Start






Reference:
https://blackboard.secure.force.com/btbb_exportarticlepdf?id=kA770000000CbF5CAK

2017年6月19日 星期一

Windows server local polocy



STEP:

To open the Local Group Policy Editor from the command line

  • Click Start , type gpedit.msc in the Start Search box, and then press ENTER .

Note:

這裡值得特別一提的就是 強制執行密碼原則 (Enforce password policy),當勾選的時候,該 SQL Server 帳戶就會使用本機安全性原則的「帳戶鎖定原則」去限制帳戶登入的次數與鎖定的時間,如下圖所示:
所以,就算你的 sa 帳戶被鎖定,其實你可以慢慢等 15 分鐘,該帳號就可以重新嘗試登入了!(當然,如果連密碼都忘記的話,那就用上述的解法吧!)


Reference: 

lightweight web server


Introudctuion:
 I was find the good and useful web server ,except for large apache tomcat , there I feel the two is famous and useful,


Product:
Nginx

Nginx has become one of the most important web servers over the last couple of years. There’s a reason for that. Instead of using the standard threaded- or process-oriented architecture, it uses a scalable, event-driven (asynchronous) architecture. So not only is it incredibly light weight, it’s highly scalable and memory usage is far better suited for limited resource deployments. Nginx also handles simple load balancing, fault tolerance, auto-indexing, virtual servers (both name- and IP-based), mod_rewrite, access control, and much more. Nginx can also serve as a reverse proxy and an IMAP/POP3 proxy server.


Jetty:

Jetty is pretty lightweight, but it does provide a servlet container, which may contradict your requirement against using an "application server".

You can embed the Jetty server into your application. Jetty allows EITHER embedded OR servlet container options.



REFERENCE:
https://www.linux.com/news/which-light-weight-open-source-web-server-right-you
https://opensource.com/business/16/8/top-5-open-source-web-servers
https://stackoverflow.com/questions/2717294/create-a-simple-http-server-with-java



2017年6月15日 星期四

Centos tar file

tar xvzf file-1.0.tar.gz - tgfo uncompress a gzip tar file (.tgz or .tar.gz)
tar xvjf file-1.0.tar.bz2 - to uncompress a bzip2 tar file (.tbz or .tar.bz2) to extract the contents.
tar xvf file-1.0.tar - to uncompressed tar file (.tar)
tar xvC /var/tmp -f file-1.0.tar - to uncompress tar file (.tar) to another directory



x = eXtract, this indicated an extraction c = create to create )
v = verbose (optional) the files with relative locations will be displayed.
z = gzip-ped; j = bzip2-zipped
f = from/to file ... (what is next after the f is the archive file)
C = directory. In c and r mode, this changes the directory before adding the following files. In x mode, changes directoriy after opening the archive but before extracting entries from the archive.

How to install blat on centos7


How to install blat


First :  (https://www.mail-archive.com/genome@soe.ucsc.edu/msg04337.html)


You need the libpng headers.  On Fedora/Centos etc. systems, you'll need:

libpng-devel

or

libpng-dev



Installing BLAT  (ref: http://nix-bio.blogspot.tw/2013/10/installing-blat-and-blast.html)

It's been a while since I last installed BLAT and when I went to the download directory at UCSC: http://users.soe.ucsc.edu/~kent/src/ I found that the latest blast is now version 35 and that the code to download was: blatSrc35.zip. However, you can also get pre-compiled binaries at: http://hgdownload.cse.ucsc.edu/admin/exe/ and that there was a linux x86_64 executable for my architecture available at: http://hgdownload.cse.ucsc.edu/admin/exe/linux.x86_64/blat/. Though YYMV, BLAT can be a little bit of a tricky beast to get going, so I decided to download the source code and compile that.

I will be compiling this code as 'root' as a system tool in /usr/local/src, so do not scream at me for that.

First I created an /usr/local/src/blat directory and I copied the blatSrc35.zip file into that.

Next I used

unzip blatSrc35.zip


to unpack the archive. This gives a directory blatSrc now move into that directory.

#cd blatSrc


before you begin read the README file that comes with the source code.

One thing about building blat is that you need to set the MACHTYPE variable so that the BLAT sources know what type of machine you are compiling the software on.

on most *nix machines, typing

echo $MACHTYPE

will return the machine architecture type.

On my CentOS 6 based system this gave:

x86_64-redhat-linux-gnu

However, what BLAT requires is the 'short value' (ie the first part of the MACHTYPE). To correct this, in the bash shell type (change this to the correct MACHTYPE for your system)

MACHTYPE=x86_64
export MACHTYPE


now running the command:

echo $MACHTYPE


should give the correct short form of the MACHTYPE:

x86_64

now create the directory lib/$MACHTYPE in the source tree. ie:

mkdir lib/$MACHTYPE

For my machine, lib/x86_64 already existed, so I did not have to do this, but this is not the case for all architectures.

The BLAT code assumes that you are compiling BLAT as a non-privileged (ie non-root) user. As a result, you must create the directory for the executables to go into:

mkdir ~/bin/$MACHTYPE

If you are installing as a normal user, edit your .bashrc to add the following (change the x86_64 to be your MACHTYPE):

export PATH=~/bin/x86_64::$PATH

For me, though, this was not good enough. I wanted the executables in /usr/local/bin where all my other code goes. As a result I did some hackery...

There is a master make template in the inc directory called common.mk and I edited this file with the command:

vi inc/common.mk

I replaced the line
    BINDIR=${HOME}/bin/${MACHTYPE}

with
    BINDIR=/usr/local/bin


saved and quit (as this is in my path, I do not need to do anything else)

All the preparation is now done and you can create the blat executables by going into the toplevel of the blat source tree (for me it was /usr/local/src/blat/blatSrc, but change to wherever you unpacked blat into).

Now simply run the command:

make


to compile the code.

Blat installed cleanly and the executables were all neatly placed in /usr/local/bin/x86_64, just like I wanted.

now simply running the command:

blat


on the command line gives me information on blat and sample usage.

Blat is installed and it's installed properly in my system code tree!!!

2017年6月14日 星期三

virtualbox CentOS7 networking setting


please reference the following article:
http://jimc1682000.blogspot.tw/2015/09/centos-7-virtualbox.html