2008年1月29日 星期二

JSP 多餘的斷行 錯誤

一個初學者較常犯但不容易檢查出的錯誤可能是「多餘的斷行」,例如:
  • errorDemo.jsp
 <%@page contentType="charset=Big5"
errorPage="errorHandler.jsp"%>
<%
throw new Exception("這是一個假裝的錯誤,純綷丟出例外");
%>
//←(斷行)

這個JSP程式乍看之下沒有錯誤,程式只是丟出一個例外而已,但注意到它最底下空了一行,在轉換為Servlet之後,這一行會實際轉換為 out.write('\r');,而在這行之前,由於直接丟出了一個例外,換句話說,out.write('\r');這行永遠不會被執行到,這個邏輯 錯誤,編譯器是可以檢查的出的,因而錯誤頁面會回報"unreachable statement",改正這個錯誤的方式,是將JSP頁面中多餘的斷行刪掉。

debian 重灌步驟

1.安裝及設置sudo
2./etc/apt/source.list 加入contrib non-free
3./etc/apt/source.list 加入 debian-multimedia 及 gcin 官方載點
4.安裝k7版linux-image
5.安裝nvidia官方driver
6.下載alsa driver 並 ./configure;make;sudo make install
7.sudo alsaconf
8.安裝bzip2 、 unrar
9.移動noseeing.gtab 到 /usr/share/gcin/table
10.安裝flashplugin-nonfree
11.安裝w32codecs 、 mplayer
12.安裝openssh-server 、 no-ip
13.下載安裝光碟iso檔 並設定fstab自動掛載到/media/cdrom0
14.安裝 jdk 、 eclipse
15.安裝gaim
16.copy stardict的字典到/usr/share/stardict/dic下並解開
17.設定gaim stardict 自動啟動

以上有點按又有點不按順序~^^

2008年1月28日 星期一

Jetty 6 handler 階層

1.root 是server

server -> HandlerCollection -> ContextHandlerCollection (pathmap) -> ContextHandler
而如果ContextHandler是屬於WebAppContext的話。其下包含了一連串的handler
WebAppContext -> SessionHandler -> SecurityHandler -> ServletHandler

原文:

  1. The Server delegates the request to the its configured handler, which is normally an instance of HandlerCollection.
    Server分派request給屬於server的handler,這常常是一個HandlerCollection的實例。

  2. The HandlerCollection acts like Jetty 5, and calls each of it's contained handlers in turn. Typically it is configured with
    a ContextHandlerCollection, a DefaultHandler and a RequestLogHandler. This allows a request to be handled by a context or the default handler, and then be passed to the request log handler.
    HandlerCollection會依序呼叫其下的每一個Handler,慣例上,其下會有ContextHandlerCollection,DefaultHandler,RequestHandler.

  3. The ContextHandlerCollection
    maintains a map of context path to lists of ContextHandlers. For a given request, each the URI is used to find matching context paths, and each is called in turn until the request is handled.
    ContextHandlerCollection維護一個path的map,根據request的URI mapping到其下對應的ContextHandler

  4. If the ContextHandler accepts a request (it may reject it due to virtual hosts), it will delegate the request to a nested handler and for the duration of that call it will set:
    • the request context path
    • the current thread context classloader
    • the resource base
    • the error handler
    • context attributes and init parameters.
  5. Typically the ContextHandler will be an instance of WebAppContext and will thus contain a nested chain of SessionHandler, SecurityHandler and ServletHandler. The request is delegated to the first handler in this chain, a SessionHandler
  6. The SessionHandler will examine the request for any session ID to be activated and will activate the mechanism for creating new sessions before delegating the request to the SecurityHandler.
  7. The SecurityHandler will check any constraints and authentication before delegating the request to the ServletHandler
  8. The ServletHandler implements the dispatch to Filters and Servlets to handle the request according to the servlet specification.
簡單範例程式
public static void main(String[] args) {
Server service = new Server();
// connector
Connector selconnector = new SelectChannelConnector();
selconnector.setPort(80);
service.setConnectors(new Connector[] { selconnector });
// thread pool
BoundedThreadPool pool = new BoundedThreadPool();
pool.setMinThreads(10);
pool.setMaxThreads(100);
service.setThreadPool(pool);
// handler collection
HandlerList handlerlist = new HandlerList();
service.setHandlers(new Handler[] { handlerlist, new DefaultHandler(), new RequestLogHandler() });
// static resource handler
ContextHandler resContext = new ContextHandler(handlerlist, "/html");
ResourceHandler reshandler = new ResourceHandler();
reshandler.setResourceBase("./html/");
resContext.setHandler(reshandler);
// dynamic resource handler
WebAppContext webappcontext = new WebAppContext(handlerlist, "./webapp/", "/webapp");

try {
service.join();
service.start();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}

debian kernel 1G以上ram支援

debaian預設安裝linux-image-`uname -r`-486
僅支援1G的ram,free -mt 可以看到只有約800mb

如要支援1G以上的ram,不需另外compile kernel
只要安裝專用的linux-image

linux-image-`uname -r`-k7
-> (amd處理器專用image)

linux-image-`uname -r`-686
-> (Intel處理器專用image)

kde 自動啟動設置

在~/.kde/AutoStart 資料夾下加入連結即可

cd ~/.kde/AutoStart
ln -s /usr/bin/gaim gaim

2008年1月21日 星期一

pietty 亂碼問題

遠端使用pietty 執行aptitude時的亂碼問題。
1.將pietty的編碼改為UTF-8
2.將pietty的字型改為fixedsys

SCTP

由於碩士學分班的報告需要,第一次接觸到了SCTP這一個協定。
http://dtim.mis.hfu.edu.tw/2006/paper/PAPER_A/140A.pdf
SCTP 主要的貢獻是對多重聯外線路的支持,一個端點可以由多於一個IP組成