2006年6月9日 星期五

JSP參數傳送編碼問題

當使用 POST 的方式傳送參數時大部分是不會遇到問題的,但是當您使用URL加參數(GET)傳送參數時,常常會遇到編碼的問題。以下為解決的方法:

1.
如果 tomcat 是 5.0.x 的話,在 conf/server.xml 中加入 URIEncoding="utf-8" 如下面所示:
<Connector port="8080"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="utf-8" />

2.
程式中需要使用 URL 傳送參數的地方改寫成
Server: "url.asp?var1=" + URLEncoder.encode(var1Value, "utf-8")
Client: "url.asp?var1=" + encodeURI(var1Value)

3.
接收參數頁則不需要再經過 var1Value = new String(request.getParameter("var1").getBytes("8859_1"), "UTF-8");
直接接收即可 var1Value = request.getParameter("var1");

4.
以上網頁全部為 utf-8 編碼

2006年5月17日 星期三

將網頁focus中的物件框線拿掉

當你點選連結或正按下按鈕時,該目標物旁邊就會出現不太雅觀的虛線框
如果要拿掉的話,只要加入一段 CSS 程式碼即可
a,area { blr:expression(this.onFocus=this.blur()) } /* for IE */
:focus { -moz-outline-style: none; } /* for Firefox */

2006年4月28日 星期五

如何利用 ASP 輸出 Excel 檔案

撰寫一支asp,內容如下

<%
Response.AddHeader "Content-Disposition", "attachment; filename=機關成員名單.xls"
Response.ContentType = "application/ms-excel"
%>
<table border="1">
<tr>
<td>編號</td>
<td>姓名</td>
<td>機關名稱</td>
<td>機關代碼</td>
<td>日期1</td>
<td>日期2</td>
</tr>
<tr>
<td>1</td>
<td>小明</td>
<td>日光燈有限公司</td>
<td style="mso-number-format:\@">0012</td>
<td style="mso-number-format:yyyy\/m\/d;\@"><%=date%></td>
<td style="mso-number-format:yyyy\"\年\"m\"\月\"d\"\日\";\@"><%=date%></td>
</tr>
</table>
<%
Response.Flush
Response.Clear
%>


說明:
1. Response.ContentType 設定輸出為 Excel
2. Response.AddHeader 用來將結果輸出成檔案,「attachment;」不加的話會變成直接由瀏覽器開啟,「filename=」用來設定檔案名稱
3. Table 的表格相對應 Excel 的儲存格
4. 若要設定儲存格格式(如文字、日期格式),則在加上style屬性,並且設定mso-number-format值。
mso-number-format 的參考方式可以利用將 Excel 另存成 XML 試算表,然後用 notepad 開啟該檔案,並參考檔案中該 Cell 所設定的 Style
如:,將「mm/dd/yy;@」套用到上面的 mso-number-format 即可。
但是特殊字元前必需加上反斜線「\」,所以正確格式為:「mm\/dd\/yy;\@」。
註: 特殊字元如:中文字、「/」、「@」、「&」...等。

參考來源: http://www.codeproject.com/aspnet/DAtaGridExportToExcel.asp

2006年3月24日 星期五

使用 jdbc 連結 MS SQL2000


try {
  Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
  String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=dbname";
  Connection con = DriverManager.getConnection(url, "userid", "password");
  Statement stmt = con.createStatement(1004, 1008);
} catch(Exception e) {
  e.printStackTrace();
}

必要的 JAR 檔來源:到 Microsoft Download Center
輸入關鍵字 jdbc 找 SQL Server 2000 Driver for JDBC Service Pack 3 下載安裝
將安裝目錄下的三個 jar (msbase.jar、mssqlserver.jar、msutil.jar) 放到所需的 lib 目錄下即可。

2006年2月16日 星期四

Install the Active Directory Schema snap-in

參考文章 Install the Active Directory Schema snap-in


  • Open Command Prompt.

  • Type:

    regsvr32 schmmgmt.dll

    This command will register schmmgmt.dll on your computer. For more information about using regsvr32, see Related Topics.

  • Click Start, click Run, type mmc /a, and then click OK.

  • On the File menu, click Add/Remove Snap-in, and then click Add.

  • Under Available Standalone Snap-ins, double-click Active Directory Schema, click Close, and then click OK.

  • To save this console, on the File menu, click Save.

  • In Save in, point to the systemroot\system32 directory.

  • In File name, type schmmgmt.msc, and then click Save.

  • To create a shortcut on your Start menu:

    • Right-click Start, click Open All Users, double-click the programs folder, and then double-click the Administrative Tools folder.

    • On the File menu, point to New, and then click Shortcut.

    • In the Create Shortcut Wizard, in Type the location of the item, type schmmgmt.msc, and then click Next.

    • On the Select a Title for the program page, in Type a name for this shortcut, type Active Directory Schema, and then click Finish.



2006年2月9日 星期四

Show MSN now playing with Foobar2000

想要讓 MSN 顯示 Foobar2000 正在播放的歌嗎?

1. 到 MSN Messenger Now Playing Plugin 下載 foo_msn 元件
2. 將 foo_msn.dll 放到 C:\Program Files\foobar2000\components 目錄下
3. 重新啟動 Foobar2000 即可

開啟 Foobar2000->Preferences,在 Components->MSN Now Playing 中可做設定

2006年1月24日 星期二

CSS Layout Techniques

CSS Layout Techniques

write html without "table" tag - 學習CSS排版的網頁


Restore CA failed (0x80090003)

今天到勞保局測試備份/還原CA
結果還原CA時發生錯誤,錯誤訊息為 "機碼錯誤 0x80090003"

後來在 DanPark's WebLog 找到解答:

Restoring Certificate Authority server fails with bad key problem

After you back up a CA private key and database, if restore task fails with bad key error (0x80090003), then you might need to import the root CA key when you install the CA server by checking "Use custom settings to generate the key pair and CA certifcate", then "Use an existing key" which allows to browse a key file to import.

Tips:

1. When you restore CA database, it expects the same CA storage path. By default, CA creates the database and log files under c:\WINDOWS\system32\certlog. When you restore to another machine, it should have the same path.

2. Enabling debug logging

- certutil -setreg ca\debug 0xffffffe3

Log files are in %systemroot%\cert*.log