2013年3月13日 星期三

提升JSP頁面響應速度的七大技巧

0

提升JSP頁面響應速度的七大技巧 方法一:在servlet的init()方法中緩存數據 當應用服務器初始化servlet實例之後,为客戶端請求提供服務之前,他會調用這個servlet的init()方法。在一個servlet的生命周期中,init()方法只會被調用一次。通過在init()方法中緩存一些靜態的數據或完成一些只需要執行一次的、耗時的操作,就可大大地提高系統性能。 例如,通過在init()方法中建立一個JDBC連接池是個最好例子,假設我們是用jdbc2.0的DataSource接口來取得數據庫連接,在通常的情況下,我們需要通過JNDI來取得具體的數據源。我們能夠想象在一個具體的應用中,假如每次SQL請求都要執行一次JNDI查詢的話,那系統性能將會急剧下降。解决方法是如下代碼,他通過緩存DataSource,使得下一次SQL調用時仍然能夠繼續利用他: public class ControllerServlet extends HttpServlet{ private javax.sql.DataSource testDS = null;   public void init(ServletConfig config) throws ServletException { super.init(config); Context ctx = null; try{   ctx = new InitialContext();  testDS = (javax.sql.DataSource)ctx.lookup("jdbc/testDS"); }catch(NamingException ne){ne.printStackTrace();} }catch(Exception e){e.printStackTrace();} }  public javax.sql.DataSource...

2013年3月11日 星期一

HTML 5 Form 的功能太強大了!!!

0

HTML 5 Form 的功能太強大了!!! http://www.w3schools.com/html/html5_form_attributes.asp 但IE的支持太差勁了 http://beta.html5test.com/ http://html5test.com/results/desktop.html http://nowills.blogspot.hk/2012/01/html5ie9iehtml5-html5shiv.html 各位老傢伙們,該學 HTML5 了 http://www.pigo.idv.tw/archives/952 First name: Last name: E-mail: Enter a date before 1980-01-01: Enter a date after 2000-01-01: Quantity (between 1 and 5): Select images: Country code: First name: Last name: E-mail: Enter a date before 1980-01-01: Enter...

JSP - Life Cycle ( Init & Destroy)

2

JSP - Life Cycle A JSP life cycle can be defined as the entire process from its creation till the destruction which is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet. The following are the paths followed by a JSP Compilation Initialization Execution Cleanup The four major phases of JSP life cycle are very similar to Servlet Life Cycle and they are as follows: JSP Compilation: When a browser asks for a JSP, the JSP engine first checks to see whether it needs to compile the page. If the page has never been compiled, or if the JSP has been modified since it was last compiled,...

2013年2月28日 星期四

用Java替中文網址轉碼:URLEncoder

0

用Java替中文網址轉碼:URLEncoder 在程式或者網頁的應用中我們常常需要把中文轉換為其他編碼 下面介紹這些也不僅僅限於轉換網址而已 在我目前的應用中只用過了JAVA 使用的函數是 URLEncoder.encode(String 字串, String 編碼) (編碼為:UTF-8, UTF-16等等) 以下是節錄自用javascript轉UTF-8編碼的編碼解碼介紹 #Java# 會處理#字元為%23,空白字元轉換為+,中文字拆開每BYTE處理為ASCII 第二個String 為Locale java.net.URLEncoder.encode(String args,String args) java.net.URLDecoder.decode(String args,String args) URLEncoder.encode("random word £500 bank $", "ISO-8859-1"); String s = "許功蓋"; URLEncoder.encode(s, "UTF-8") Java API URLEncoder http://docs.oracle.com/javase/1.4.2/docs/api/java/net/URLEncoder.html URL Encoding Reference ASCII CharacterURL-encoding space%20 !%21 "%22 #%23 $%24 %%25 &%26 '%27 (%28 )%29 *%2A +%2B ,%2C -%2D .%2E /%2F 0%30 1%31 2%32 3%33 4%34 5%35 6%36 7%37 8%38 9%39 :%3A ;%3B <%3C =%3D >%3...

Pages 14« 45678910 »