顯示具有 web 標籤的文章。 顯示所有文章
顯示具有 web 標籤的文章。 顯示所有文章

2010年7月7日 星期三

MySQL備忘錄

懶的每次要用到的時候都得重查,就寫在這吧~~~~

1. 連線
$ mysql -u <username> -h <host-name> -p
Account Management

1. 新增帳號 (密碼可空白, i.e., 空字串)
$ GRANT ALL PRIVILEGES ON *.* TO <username>@<domainname> IDENTIFIED BY '<password>' WITH GRANT OPTION;
$ GRANT ALL PRIVILEGES ON *.* TO <username>@'%' IDENTIFIED BY '<password>';
As you see in the latest example we use '%' instead of localhost, which means that our user can use all the privileges from every host.


2. Modify password
$ mysqladmin -u <user> -p <old-passwd> password <new-passwd>;
or
$mysqladmin -u <user> password <new-passwd>;

New and delete database

1.. 新增database (i.e., 用``將database-name包起來可避免含有特殊字元的問題,如dash(i.e., - ))
$ CREATE DATABASE `<database-name>`
2.. 刪除database
$ DROP DATABASE `<database-name>`


2010年4月15日 星期四

Java Web Programming 開發環境建置

WebContainer Hosting

1. 下載Tomcat (環境為ubuntu 9.10,所以下載tar.gz)

2. 設定環境變數:
export JAVA_HOME=/usr/lib/jvm/java-1.5.0-sun
3. 執行 $CATALINA_HOME/bin/startup.sh,到這裡Tomcat就起來了(可以用browser連 http://localhost:8080,可以看到經典的湯姆貓網頁)

Web Project Configuration

1. 先將eclipse裝上wtp plugin

2. New Dynamic Web Project

3. eclipse會產生3個資料夾project所在的目錄:
 i. build:eclipes預設以此dir當作build output dir.
 ii. src: 存放source code
 iii. WebContent : 會自動產生WEB-INF, META-IN兩個資料夾, 網頁檔(jsp, html)會放在此處

4. 由於tomcat預設classes是在WEB-INF底下,所以在eclipse裏面剛new 出來的project設定property以 將output path改為WebContent/WEB-INF/classes

5. 在$CATALINA_HOME/conf/server.xml的中增加內容如下
Context path="/test" docBase="/home/funkie/data/document/eclipse_workspace/DMServer/WebContent"
debug="0" reloadable="true" crossContext="true" />
docBase: 為project 網頁的實體路徑
path: 為append在url的路徑名稱,如http://localhost:8080/test/ 就會連到 <略>/DMServer/WebContent/index.html

基本上這樣開發環境就搞定啦~~~~


Servlet

先寫個servlet來小試身手一下,在eclipse中的project按左鍵就有new servlet的選項可以選啦~~

基本上一個servlet要能work必須:
1. extends HttpServlet及implement doGet()和doPost().
2. 於WEB-INF/web.conf中declare該servlet,如下
<display-name>ServletTest</display-name>
<servlet-name>ServletTest</servlet-name>
<servlet-class> MyServlet2.ServletTest</servlet-class>
<servlet-mapping>
<servlet-name>ServletTest</servlet-name>
<url-pattern>/ServletTest</url-pattern>
</servlet-mapping>
3. compile的時候要include $CATALINA_HOME/lib/servlet-api.jar

最後用http://localhost:8080/test/ServletTest就可以連到該servlet了。其中,test為$CATALINA_HOM/conf/server.xml設定的context path,ServletTest為WEB-INF/web.conf設定的url-pattern


P.S.
  今天遇到一個白爛問題害我搞超久,由於平常都在寫android,所以一直使用jdk1.5 (因此tomcat也是使用1.5,i.e., 我有export JAVA_HOME),可是今天在web的project中用1.6 compile servlet,結果在啟動tomcat時就這樣起都起不來。

除了設定eclipse project的compiler外,還有個叫作"Project Facets"裏面的java選項也要改成1.5,
就是這東西害我今天搞超久.....囧。

2009年5月19日 星期二

2009年3月26日 星期四

http404 解決經驗


察看檔案權限!!!

(慘痛經驗:Tomcat&jsp, gitweb看不到某些repository,)