2014年12月3日 星期三

安裝 install Tomcat on linux

安裝文參考:

Nginx+tomcat整合安装配置

Virtual Host + Nginx + Tomcat

http://hosseinkaz.blogspot.tw/2012/06/setting-up-jdk-path-javahome-for.html

 sudo apt-get install tomcat7

~$ sudo service tomcat7 start 出現以下錯誤訊息
Job for tomcat7.service failed. See 'systemctl status tomcat7.service' and 'journalctl -xn' for details.
-- Unit tomcat7.service has begun starting up.
依照指示執行
~$  systemctl status tomcat7.service

出現此訊息
~$ sudo systemctl status tomcat7.service
tomcat7.service - LSB: Start Tomcat.
   Loaded: loaded (/etc/init.d/tomcat7)
   Active: failed (Result: exit-code) since 四 2014-12-04 03:43:40 CST; 2min 36s ago
  Process: 1494 ExecStart=/etc/init.d/tomcat7 start (code=exited, status=1/FAILURE)

12月 04 03:43:40 TAHITI systemd[1]: Starting LSB: Start Tomcat....
12月 04 03:43:40 TAHITI tomcat7[1494]: no JDK or JRE found - please set JAV...!
12月 04 03:43:40 TAHITI systemd[1]: tomcat7.service: control process exite...=1
12月 04 03:43:40 TAHITI systemd[1]: Failed to start LSB: Start Tomcat..
12月 04 03:43:40 TAHITI systemd[1]: Unit tomcat7.service entered failed state.
Hint: Some lines were ellipsized, use -l to show in full.

或~$ journalctl -xn'
-- Logs begin at 四 2014-12-04 03:38:33 CST, end at 四 2014-12-04 03:59:43 CST.
12月 04 03:53:10 TAHITI systemd[1]: Starting Cleanup of Temporary Directories...
-- Subject: Unit systemd-tmpfiles-clean.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
........
12月 04 03:59:43 TAHITI tomcat7[1640]: no JDK or JRE found - please set JAVA_HOME
12月 04 03:59:43 TAHITI systemd[1]: tomcat7.service: control process exited, cod
12月 04 03:59:43 TAHITI systemd[1]: Failed to start LSB: Start Tomcat..
-- Subject: Unit tomcat7.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
........

確定環境都有設定好
~$ javac -version
javac 1.8.0_25
~$ which javac
/usr/bin/javac
~$ which java
/usr/bin/java

~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
~$  echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle
可是仍然出現沒設好JAVA_HOME訊息
no JDK or JRE found - please set JAVA_HOME


參考:Specify JDK for tomcat7
Setting up jdk path (JAVA_HOME) for Tomcat7 in ubuntu
這時要編輯tomcat設定檔

(也有人說ubuntu下/etc/profile?加上export JAVA_HOME=/usr/local/java/jdk1.8.0_{xx})
/etc/default/tomcat7

註解掉的那一行#JAVA_HOME=/usr/lib/jvm/openjdk-6-jdk
改為設定 sets the JAVA_HOME variable:JAVA_HOME=/usr/lib/jvm/java-8-oracle  
重新restart~$  sudo service tomcat7 start
http://localhost:8080


~$ /usr/share/tomcat7/bin/startup.sh
Using CATALINA_BASE:   /usr/share/tomcat7
Using CATALINA_HOME:   /usr/share/tomcat7
Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
Using JRE_HOME:        /usr/lib/jvm/java-8-oracle
Using CLASSPATH:       /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
touch: cannot touch ‘/usr/share/tomcat7/logs/catalina.out’: 沒有此一檔案或目錄

/usr/share/tomcat7/bin/catalina.sh: 385: /usr/share/tomcat7/bin/catalina.sh: cannot create /usr/share/tomcat7/logs/catalina.out: Directory nonexistent

tomcat7's CATALINA_HOME in Debian/Ubuntu

It is under /usr/share/tomcat7/.
One way to find the location is to look into the service startup script /etc/init.d/tomcat7/. You will find these lines in it:
NAME=tomcat7
...
CATALINA_HOME=/usr/share/$NAME
測試下列設定
echo $JAVA_HOME
echo $CATALINA_HOME
echo $CLASSPATH

How to set JAVA_HOME or CATALINA_HOME if I have more than 1 version used for Projects?

Inside the tomcat startup script /bin/catalina.sh, the following environmental variables are used:
  • JAVA_HOME is the path of JDK that used to run the tomcat and web applications
  • CATALINA_HOME is the path of the tomcat binaries files
  • CATALINA_BASE is the path the tomcat configuration files
So , how about this approach? For example :
Install JDK 5.0 to : /opt/jdk5
Install JDK 6.0 to : /opt/jdk6
Install tomcat 6.0 to :/opt/tomcat6
Install tomcat 7.0 to : /opt/tomcat7 
Each of your web application has their own folder to hold their own tomcat 's configuration. For example :/home/web1 for the web application 1
/home/web2 for the web application 2

其他錯誤解決方法

 [tomcat7] systemd service starting problems

One of user suggest to increase "-wait" parameter in "/usr/lib/systemd/system/tomcat7.service".

Configure Tomcat Server

接下來有關Linux上tomcat 配置
有四個主要xml設定檔
  1. server.xmlSet the TCP Port Number
  2. web.xmlEnabling Directory Listing
  3. context.xmlEnabling Automatic Reload  
  4. tomcat-users.xml.

Tomcat設定SSL憑證

if your web wants to provide HTTPS that needs  SSL support  ,which is, data being sent is encrypted by one side, transmitted, then decrypted by the other side before processing
 certification(self-signed SSL certification or public certificaton)
請參考SSL your Tomcat 7+Tomcat - SSL操作大全 

 JKSPKCS11 or PKCS12 format keystores
The JKS format is Java's standard "Java KeyStore" format, and is the format created by the keytool command-line utility. This tool is included in the JDK. The PKCS12 format is an internet standard, and can be manipulated via (among other things) OpenSSL and Microsoft's Key-Manager.


OpenSSL implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS) protocols. 

用keytool產生鑰匙.keystore 檔(Keytool 是一個JAVA環境下的安全鑰匙與憑證的管理工具)
uses “keytool” command to create a self-signed certificate


$JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA \
  -keystore /path/to/my/keystore
$tomcat7\bin>keytool -genkey -alias tomcat -keyalg RSA -validity 365 -keystore Mykeystore 

~$ $JAVA_HOME/bin/keytool -genkey -alias tomcat -keyalg RSA -validity 365 -keystore mykeystore.jks
產生一個叫mykeystore.jks檔
輸入金鑰儲存庫密碼:  yourpassword你的密碼
重新輸入新密碼: yourpassword你的密碼
您的名字與姓氏為何?
  [Unknown]:  coco liu
您的組織單位名稱為何?
  [Unknown]:  internet
您的組織名稱為何?
  [Unknown]:  internet
您所在的城市或地區名稱為何?
  [Unknown]:  taichung
您所在的州及省份名稱為何?
  [Unknown]:  taiwan
此單位的兩個字母國別代碼為何?
  [Unknown]:  tw
CN=coco liu, OU=internet, O=internet, L=taichung, ST=taiwan, C=tw 正確嗎?
  [否]:  y
輸入 的金鑰密碼yourpassword你的密碼
(RETURN 如果和金鑰儲存庫密碼相同):  
重新輸入新密碼:yourpassword你的密碼

根據這個jks檔產生一個csr檔,輸入命令:
keytool -certreq -alias tomcat -keystore server.jks -file server.csr

顯示keystore的資訊.
/etc/tomcat7/conf$ keytool -list -v -keystore mykeystore.jks
輸入金鑰儲存庫密碼: yourpassword你的密碼


金鑰儲存庫類型: JKS
金鑰儲存庫提供者: SUN

您的金鑰儲存庫包含 1 項目

別名名稱: tomcat
建立日期: 2014/12/4
項目類型: PrivateKeyEntry
憑證鏈長度: 1
憑證 [1]:
擁有者: CN=coco liu, OU=internet, O=internet, L=taichung, ST=taiwan, C=tw
發出者: CN=coco liu, OU=internet, O=internet, L=taichung, ST=taiwan, C=tw
序號: 4507a287
有效期自: Thu Dec 04 21:57:29 CST 2014 到: Fri Dec 04 21:57:29 CST 2015
憑證指紋:
MD5:  4A:DE:B1:B5:79:D0:C5:E7:E5:BC:E5:92:E0:5B:84:25
SHA1: 6A:AB:96:4F:79:77:52:27:31:23:C2:74:5C:F4:4A:9B:DA:B5:6A:3F
SHA256: 54:63:32:7E:34:76:A5:38:15:77:50:7B:15:C6:BB:CB:68:B2:DC:0D:42:C0:E7:39:60:0E:4A:87:0C:E2:A6:BB
簽章演算法名稱: SHA256withRSA
版本: 3
擴充套件: 
#1: ObjectId: 2.5.29.14 Criticality=false
SubjectKeyIdentifier [
KeyIdentifier [
0000: 0D 77 41 E6 8E 29 CC DC   E7 6F A3 0F 05 45 E5 4C  .wA..)...o...E.L
0010: 7E DF D0 D7                                        ....
]
]
*******************************************
*******************************************

Keytool命令行參數說明:
參數說明
-genkey在用戶主目錄中建立一個預設檔".keystore",還會產生一個mykey的別名,mykey中包含用戶的公鑰、私鑰和憑證
-alias別名
-keystore指定密鑰庫的名稱(產生的各類資訊將不在.keystore文件中
-keyalg指定密鑰的演算法
-validity指定建立的憑證有效期多少天
-keysize指定密鑰長度
-storepass指定密鑰庫的密碼
-keypass指定別名條目的密碼
-dname指定憑證擁有者資訊 例如: "CN=sagely,OU=atr,O=szu,L=sz,ST=gd,C=cn"
-list顯示密鑰庫中的憑證詳細資訊
-export將別名指定的憑證導出到文件 keytool -export -alias caroot -file caroot.crt
-file參數指定導出到檔的檔案名
-delete刪除密鑰庫中某條目
-keypasswd修改密鑰庫中指定條目口令 keytool -keypasswd -alias sage -keypass .... -new .... -storepass ... -keystore sage
-import將已簽名數位憑證導入密鑰庫 keytool -import -alias sage -keystore sagely -file sagely.crt
導入已簽名數位憑證用keytool -list -v 以後可以明顯發現多了認證鏈長度,並且把整個CA鏈全部列印出來


根據產生的keystore 修改tomcat設定檔sever.xml(沒有APR的Tomcat)
為伺服器加入自己產生的憑證
拿掉下列Connector標籤註解
加入 keystoreFile="conf/mykeystore.jks"產生的鑰匙位置
和 keystorePass="yourpassword你的密碼" 輸入的密碼

   

改為
   
               maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS"
               keystoreFile="conf/mykeystore" keystorePass="yourpassword你的密碼" />


瀏覽https://localhost:8443/
就會出現有些網站用https瀏覽時瀏覽器跳出憑證不安全的提示(因為是自己產生的憑證)



Tomcat can use two different implementations of SSL:
  • the JSSE implementation provided as part of the Java runtime (since 1.4)
  • the APR implementation, which uses the OpenSSL engine by default.
APR 連接器
Tomcat還有一個特殊的模組:APR(Apache Portable Runtime)是為了提高Tomcat處理靜態內容性能,提供的元件,其實就是以Apache2.0為核心的一個http服務。在HTTPS方面,APR和Apache一樣採用Openssl,在憑證安裝部分,會簡要說明一下。
Tomcat支援Jave Keystore檔格式作為SSL憑證存儲用途。Java Keystore文件的常見副檔名有.jks和.key。要製作JKS檔,有2種主要方式:
  1. 用JRE自帶的Keytool工具。先產生一個新的jks檔,並到處一個csr檔,然後將csr發給CA簽名,並將簽名後的文件導入jks文件。
  2. 用openssl工具,製作key和csr文件,將csr發給CA簽名得到cer檔,然後將key和cer合併成一個jks檔。


產生certificate

/etc/tomcat7/conf$ sudo keytool -certreq -alias tomcat -keystore /etc/tomcat7/conf/mykeystore.jks -file mycertificate.csr
[sudo] password for user: 
輸入金鑰儲存庫密碼:yourpassword你的密碼
將保存好的.cer檔和製作CSR時候生成的.key一起複製到伺服器上。

將server.cer檔內容複製利用線上工具P7B線上轉換工具轉換為P7B檔保存為cert.txt。
然後將CA簽好的憑證文件cert.txt導入jks文件:
keytool -import -keystore mykeystore.jks -alias tomcat -file cert.txt

P7B檔案是主要與PKCS #7 Certificate相關的Web Files。


tomcat SSL Configuration HOW-TO
http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html
How To Configure Tomcat To Support SSL Or Https

WIS 匯智
WIS 匯智 SSL 數位憑證Keytool工具介紹

Tomcat 設定技巧 - Top 10 


~$ systemctl status tomcat7.service
Failed to get D-Bus connection: Failed to connect to socket /var/run/dbus/system_bus_socket: 沒有此一檔案或目錄
~$ journalctl -xn

$ sudo service tomcat7 restart
Job for tomcat7.service failed. See 'systemctl status tomcat7.service' and 'journalctl -xn' for details.
$ systemctl status tomcat7.service
Failed to get D-Bus connection: Failed to connect to socket /var/run/dbus/system_bus_socket: 

$ journalctl -xn
-- Logs begin at 五 2014-12-05 04:36:41 CST, end at 五 2014-12-05 05:53:44 CST. --
12月 05 05:53:39 TAHITI sudo[2304]: ayu : TTY=pts/0 ; PWD=/etc/tomcat7 ; USER=root ; COMMAND=/u
12月 05 05:53:39 TAHITI sudo[2304]: pam_unix(sudo:session): session opened for user root by ayu
12月 05 05:53:39 TAHITI systemd[1]: Stopping LSB: Start Tomcat....
-- Subject: Unit tomcat7.service has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit tomcat7.service has begun shutting down.
12月 05 05:53:39 TAHITI tomcat7[2309]: Stopping Tomcat servlet engine: tomcat7.
12月 05 05:53:39 TAHITI systemd[1]: Starting LSB: Start Tomcat....
-- Subject: Unit tomcat7.service has begun with start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit tomcat7.service has begun starting up.
12月 05 05:53:44 TAHITI tomcat7[2320]: Starting Tomcat servlet engine: tomcat7 failed!
12月 05 05:53:44 TAHITI systemd[1]: tomcat7.service: control process exited, code=exited status
12月 05 05:53:44 TAHITI systemd[1]: Failed to start LSB: Start Tomcat..
-- Subject: Unit tomcat7.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit tomcat7.service has failed.
-- 
-- The result is failed.
12月 05 05:53:44 TAHITI systemd[1]: Unit tomcat7.service entered failed state.
12月 05 05:53:44 TAHITI sudo[2304]: pam_unix(sudo:session): session closed for user root


安裝Tomcat on Windows

Tomcat
目錄架構
"bin"資料夾-主要是存放Tomcat服務啟動相關的執行檔(可設定)
"conf"資料夾主要是存放Tomcat伺服器(容器系統)相關的設定。
"webapps"資料夾主要是存放Tomcat管理網站及JSP網站佈署的地方
"lib"資料夾網站所需套件如servlet-api.jar和jsp-api.jar
"log"資料夾-檢查error messages

1.安裝jdk後
設定環境變數path
C:\Program Files (x86)\Java\jdk1.8.0_25\bin
 classpath
.;C:\Program Files (x86)\Java\jdk1.8.0_25\lib;C:\Program Files (x86)\Java\jdk1.8.0_25\lib\tools.jar

2.下載tomcat zip解壓縮後
設定環境變數
或cmd命令提示字元執行
或在bin資料夾底下setclasspath.bat這個檔案,按右鍵"編輯"加入此兩行
set JAVA_HOME=C:\Program Files (x86)\Java\jdk1.8.0_25
set JRE_HOME=C:\Program Files (x86)\re1.8.0_25


執行servlet或JSP
set CLASSPATH=%CLASSPATH%;d:\tomcat7\lib\servlet-api.jar;d:\tomcat7\lib\jsp-api.jar

若有設定 CATALINA_HOME
set CATALINA_HOME=C:\tomcat7
就可以改寫成下列形式
執行servlet加入   %CATALINA_HOME%\common\lib\servlet-api.jar
執行JSP加入 %CATALINA_HOME%\common\lib\jsp-api.jar

跑tomcat指令改為
cmd命令提示字元執行
  - Execute the shell command:

      %CATALINA_HOME%\bin\startup             (Windows)
或是
      cd %CATALINA_HOME%\bin                  (Windows)
      startup                                 (Windows)


要設定CATALINA_HOME代表tomcat安裝的目錄
In the remainder of this manual, example shell scripts assume that you have set an environment variableCATALINA_HOME that contains the pathname to the directory in which Tomcat has been installed. 

Optionally, if Tomcat has been configured for multiple instances, each instance will have its ownCATALINA_BASE configured.tomcat有多個user使用該tomcat環境才要設定

打開瀏覽器
http://localhost:8080/
      http://127.0.0.1:8080/

關掉tomcat 
cmd執行
 %CATALINA_HOME%\bin\shutdown            (Windows)
或是
   cd %CATALINA_HOME%\bin                  (Windows)
   shutdown                                (Windows)

不想用預設8080port 改 $CATALINA_HOME/conf/server.xml設定
出現"out of environment space" error錯誤可更改startup.bat的Memory設定
找不到localhost要設定瀏覽器proxy configuration



參考:
http://tomcat.apache.org/tomcat-4.1-doc/RUNNING.txt
http://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt
http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html
http://web.nchu.edu.tw/~jlu/cyut/tomcat7.shtml

How to set CATALINA_HOME variable in windows 7?Tomcat安裝步驟

[Apache_Tomcat] Tomcat 安裝教學

2014年12月2日 星期二

Linux sudo 加入使用者

步驟1.
用root權限加入#useradd UserXXX  (不會主動建立家目錄)
若已建立過user會出現#useradd: user 'UserXXX ' already exists

步驟2.
設定密碼passwd UserXXX 
輸入新的 UNIX 密碼:
再次輸入新的 UNIX 密碼:
passwd:密碼已成功地變更

此時尚未加入sudoers檔案
執行#sudo UserXXX出現
#UserXXX is not in the sudoers file.  This incident will be reported.
步驟3.
編輯vi /etc/sudoers 或
執行 #visudo(編輯/etc/sudoers.tmp)
root ALL=(ALL) ALL這行底下加入
UserXXX ALL=(ALL) ALL

sudo adduser  sudo
The change will take effect the next time the user logs in.
This works because /etc/sudoers is pre-configured to grant permissions to all members of this group (You should not have to make any changes to this):
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
As long as you have access to a user that is in the same groups as your "original" user, you can delete the old one.

Realistically, there are also other groups your new user should be a member of. If you set the Account type of a user to Administrator in Users Settings, it will be placed in at least all of these groups:
adm sudo lpadmin sambashare
Because your system configuration may vary, I suggest taking a look at the output of groups  to see what groups are normally in use.

Open a Root Terminal and type visudo (to access and edit the list).
Navigate to the bottom of the sudoers file that is now displayed in the terminal.
Just under the line that looks like the following:
    root ALL=(ALL) ALL
Add the following (replacing user with your actual username):
    user ALL=(ALL) ALL
Now save the file. The procedure for this will depend on your editor:
  • nano – CtrlO then Enter, then CtrlX to exit
  • vim – :wq

參考
sudo-user

How can I add a new user as sudoer using the command line?

My main username is not in the sudoers file


Debian裝在VMWare上 突然無法顯示ip 無法取得IPv4 Address只有IPv6

前幾天打開VM的時候原本用XShell可以連到linux系統的ip突然不能用了
後來直接VM安裝的linux終端機執行指令ifconfig
只有得到MAC實體位址和IPv6位址
搜尋的問題向網路上一些文章一樣
找不到eth0對應的IPv4 Address
eth0 Link encap:Ethernet HWaddr e8:03:9a:97:61:b1 inet6 addr: fe80::ea03:9aff:fe97:61b1/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:29576 errors:0 dropped:1 overruns:0 frame:0 TX packets:17045 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:37185910 (37.1 MB) TX bytes:1622658 (1.6 MB) Interrupt:20 Memory:f7100000-f7120000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:1289 errors:0 dropped:0 overruns:0 frame:0 TX packets:1289 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:114509 (114.5 KB) TX bytes:114509 (114.5 KB)

根據文章的解法把IPv6取消或是設定eth0,NAT,DHCP
重新restart networking似乎都沒有得到解決的方法
因為在window的cmd執行arp-a或ipconfig都沒有找到相對應的實體位址
目前懷疑是vm的ip位址沒有分配好
後來重灌VM Tool(留下虛擬機安裝的系統)後執行ifconfig就正常了

雖然沒找出真正原因
筆記一下,希望之後熟悉後若再遇到,能夠找到解決方法或有高手可以指點一二


參考

VirtualBox: two network interfaces (NAT and host-only ones) in a Debian guest on Ubuntu

Inability to use IPv4-mapped IPv6 on debian squeeze

備註:
------解決思路---------------------- 
1.查看網卡是否正常連接。 
mii-tool eth0; 
2.查看網絡配置 那就接份了。 

2014年11月26日 星期三

Netbeans

NetBeans ShortCut 常用快速鍵

F6:程序運行快捷鍵

Ctrl + F:尋找
F3:尋找下一個字串
Ctrl + G:跳到第 N 行
Ctrl + H:取代

Tab:增加縮排
Shift + Tab:減少縮排
Ctrl + E:刪除一行
Shift+Enter:在該行下一行新建一條空白
右鍵   : 格式化代碼
/**註解
Ctrl+/ 或Ctrl+Shift+C:註釋和取消註釋(選中多行,可以多行注釋)
ctrl+\ : 代碼提示
Ctrl + Shift + I:修正 import 項目
Alt + Enter:修正程式碼錯誤
Alt + Shift + F:格式化程式碼
Alt + Insert:產生程式碼 (constructor、get method、set method....)
Ctrl + Up↑ / Down:向上、下捲動
Ctrl + R:重新命名
Ctrl + \:自動完成、程式碼建議
Ctrl + Page Down:下一個分頁
Ctrl + Page UP↑:上一個分頁
Alt + Shift + Up↑:整行向前移動
Alt + Shift + Down:整行向後移動
Alt + Shift + Enter:全螢幕
Ctrl + Shift +  Up↑:整行複製
Ctrl + 數字鍵盤「+」號:展開目前程式碼片段
Ctrl + 數字鍵盤「-」號:縮合目前程式碼片段
Ctrl + Shift + 數字鍵盤「+」號:展開所有程式區段
Ctrl + Shift + 數字鍵盤「-」號:縮合所有程式區段


Tips
Code Completion: Ctrl-Space or Ctrl-\
Code Templates: 縮寫 + Space
請至 Tools-->Options-->Editor Code Templates
Code hints: Alt+Enter

find class Shift+Alt+O

Shift + F1: 開啟Java doc搜尋
設定使用Javadoc: Shift+F1
Tools --> Java Platform Manager
Tools -- > Library Manager

其他:觀看 Source & Refactor
Ctrl + G:Go to Line (與 eclipse 一樣)
Alt + Shift + O:Go to Class
Alt + O:Go to Source
Ctrl + B:Go to Super Implementation
Alt + F7:Find Usages
Ctrl + F:Find
Ctrl + H:Replace
Ctrl + Shift + P:Find in projects
Ctrl + Shift + 1:Select in project
Shift + F3:Find Previous
F3:Find Next

Ctrl+數字:切換視窗
Ctrl + 7:導覽窗
Ctrl + 0:編輯窗
Ctrl + 1:專案窗
Ctrl + 2:檔案窗
Ctrl + 2:輸出窗

Alt + Shift + R:rename, 改名稱 (與 eclipse 一樣)
Alt + Shift + F:Fix Imports, 自動 Import
Alt + Shift + W:Surround With try-catch, 自動 try catch
Alt + 左,右 :切換來源檔;切換分頁
Alt + Enter :建議與修正

Ctrl + Shift + F:Reformat Code,自動排版 (與 eclipse 一樣)
Ctrl + Shift + T:Comment, 註解
Ctrl + Shift + D:Uncomment, 反註解
Ctrl + F3:Find Selection,搜尋選擇的字串
Ctrl + l or k :自動完成字串
sout + white space : Code template

更改介面字型:
在啟動捷徑裡面,設定起始參數
加上 --fontsize 12 看起來字會比較大
加上 --laf javax.swing.plat.metal.MetalLookAndFeel 字會比較美觀

其他修改界面風格
SunONE Studio 5中文版默認啟動時的界面風格是metal的(也就是java的那種風格),可
以按照swing程序的標準修改方式進
行更換,如更換為windows風格等,如下:
更換為windows風格: --laf com.sun.java.swing.plaf.windows.WindowsLookAndFeel
更換為metal風格(默認): --laf javax.swing.plaf.metal.MetalLookAndFeel
更換為motif風格: --laf com.sun.java.swing.plaf.motif.MotifLookAndFeel
更換為mac風格: --laf com.sun.java.swing.plaf.mac.MacLookAndFeel
更換為GTK風格: --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel

設定編輯器字型:
編輯器全域字型建議請設定為 dialogInput 14
修改語言
如果你想使用英文版的NB,那麼只需要在那個"C:\Program
Files\netbeans-5.5\bin\netbeans.exe" 後面加一個 -locale en,即快捷方式的屬性中
的目標欄為
"C:\Program Files\netbeans-5.5\bin\netbeans.exe" -locale en
就OK了。我一般是把預設的快捷方式複製一份,再改那麼,這樣就有中文,英文兩個版本
的快捷方式了。



編輯字體
編輯format格式
編輯行尾ending


文件參考出處:
NetBeans5.5 繁中下載 http://www.netbeans.info/downloads/index.php?rs=11

NetBeans overview  http://0rz.tw/d72JM

NetBeans IDE 5.5 Quick Start Guide
http://www.netbeans.org/kb/55/quickstart.html

Basic Programming http://www.netbeans.org/kb/trails/java-se.html
http://bbs.csdn.net/topics/350131767
https://netbeans.org/kb/73/java/editor-codereference_zh_CN.html
http://iambigd.blogspot.tw/2010/11/eclipse.html

2009年11月19日 星期四

tomcat解決ie開啟rar檔呈現亂碼的問題

1.
因為容器系統必須告訴瀏覽器要以什麼型式打開文件
而TOMCAT在默認情況下載.rar的文件是當作text打開文件
所以ie在打開rar檔時會呈現亂碼
在目錄conf底下的web.xml加入下面的程式碼後,在重開TOMCAT
<mime-mapping>

<extension>zip</extension>

<mime-type>application/zip</mime-type>

</mime-mapping>


同理,當其他文件也沒法正常以應用程是顯示的話
也是用這樣的方式在tomcat加上開啟該類文件的程式碼
例如pdf
<mime-mapping></mime-mapping>

<extension></extension>pdf


<mime-type></mime-type>

2.
不同的ContentType 會影響客戶端所看到的效果

默認的ContentType為 text/html 也就是網頁格式

要知道更多contentype可google一下

常用ContentType
* text/plain(純文本)
* text/html(HTML文檔)
* application/xhtml+xml(XHTML文檔)
* image/gif(GIF圖像)
* image/jpeg(JPEG圖像)
* image/png(PNG圖像)
* video/mpeg(MPEG動畫)
* application/octet-stream(任意的二進位數據)
* application/pdf(PDF文檔)
* application/msword(Microsoft Word文件)
* message/rfc822(RFC 822形式)
* multipart/alternative(HTML郵件的HTML形式和純文本形式,相同內容使用不同形式表示)
* application/x-www-form-urlencoded(使用HTTP的POST方法提交的表單)
* multipart/form-data(同上,但主要用於表單提交時伴隨文件上傳的場合)

application/andrew-inset ez
application/mac-binhex40 hqx
application/mac-compactpro cpt
application/mathml+xml mathml
application/msword doc
application/octet-stream bin dms lha lzh exe class so dll
application/oda oda
application/ogg ogg
application/pdf pdf
application/postscript ai eps ps
application/rdf+xml rdf
application/smil smi smil
application/srgs gram
application/srgs+xml grxml
application/vnd.mif mif
application/vnd.mozilla.xul+xml xul
application/vnd.ms-excel xls
application/vnd.ms-powerpoint ppt
application/vnd.wap.wbxml wbxml
application/vnd.wap.wmlc .wmlc wmlc
application/vnd.wap.wmlscriptc .wmlsc wmlsc
application/voicexml+xml vxml
application/x-bcpio bcpio
application/x-cdlink vcd
application/x-chess-pgn pgn
application/x-cpio cpio
application/x-csh csh
application/x-director dcr dir dxr
application/x-dvi dvi
application/x-futuresplash spl
application/x-gtar gtar
application/x-hdf hdf
application/x-httpd-php .php .php4 .php3 .phtml
application/x-httpd-php-source .phps
application/x-javascript js
application/x-koan skp skd skt skm
application/x-latex latex
application/x-netcdf nc cdf
application/x-pkcs7-crl .crl
application/x-sh sh
application/x-shar shar
application/x-shockwave-flash swf
application/x-stuffit sit
application/x-sv4cpio sv4cpio
application/x-sv4crc sv4crc
application/x-tar .tgz tar
application/x-tcl tcl
application/x-tex tex
application/x-texinfo texinfo texi
application/x-troff t tr roff
application/x-troff-man man
application/x-troff-me me
application/x-troff-ms ms
application/x-ustar ustar
application/x-wais-source src
application/x-x509-ca-cert .crt
application/xhtml+xml xhtml xht
application/xml xml xsl
application/xml-dtd dtd
application/xslt+xml xslt
application/zip zip
audio/basic au snd
audio/midi mid midi kar
audio/mpeg mpga mp2 mp3
audio/x-aiff aif aiff aifc
audio/x-mpegurl m3u
audio/x-pn-realaudio ram rm
audio/x-pn-realaudio-plugin rpm
audio/x-realaudio ra
audio/x-wav wav
chemical/x-pdb pdb
chemical/x-xyz xyz
image/bmp bmp
image/cgm cgm
image/gif gif
image/ief ief
image/jpeg jpeg jpg jpe
image/png png
image/svg+xml svg
image/tiff tiff tif
image/vnd.djvu djvu djv
image/vnd.wap.wbmp .wbmp wbmp
image/x-cmu-raster ras
image/x-icon ico
image/x-portable-anymap pnm
image/x-portable-bitmap pbm
image/x-portable-graymap pgm
image/x-portable-pixmap ppm
image/x-rgb rgb
image/x-xbitmap xbm
image/x-xpixmap xpm
image/x-xwindowdump xwd
model/iges igs iges
model/mesh msh mesh silo
model/vrml wrl vrml
text/calendar ics ifb
text/css css
text/html .shtml html htm
text/plain asc txt
text/richtext rtx
text/rtf rtf
text/sgml sgml sgm
text/tab-separated-values tsv
text/vnd.wap.wml .wml wml
text/vnd.wap.wmlscript .wmls wmls
text/x-setext etx
video/mpeg mpeg mpg mpe
video/quicktime qt mov
video/vnd.mpegurl mxu
video/x-msvideo avi
video/x-sgi-movie movie
x-conference/x-cooltalk ice



(--提醒自己--)瀏覽器開啟檔案是依照http伺服器告訴他如何開啟文件的方式打開

伺服器會在header包含MIME(Content-Type)告訴瀏覽器他傳送的東西是屬於那一種型態

然後瀏覽器再按照該型態打開文件的方式打開