2021年12月4日 星期六

JSP網頁URL傳遞中文問題

以一般代碼維護為例:

代碼清單頁面

<% String url2 = "zzz.jsp?xxx="+ 
	java.net.URLEncoder.encode(bean.getXxx(), "Big5"); %>

  <a href="<%= url2 %>"><%=bean.getXxx() %></a>

代碼修改頁面(要取得代碼的KEY值)

<%
String xxx = java.net.URLDecoder.decode(new String(
	request.getParameter("xxx").getBytes("iso-8859-1"),"Big5"),"Big5");
%>

小插曲:

  • 我的測試環境是使用Tomcat 8.5.71
  • 起初代碼修改頁面一直無法正確接收到中文字, 因舊Tomcat URIEncoding預設ISO-8859-1,但是Tomcat8.5 改為預設UTF-8
  • 考量其他舊程式將Tomcat 8.5改回預設ISO-8859-1
 
Tomcat\conf\server.xml :
<connector connectiontimeout="20000" port="80" protocol="HTTP/1.1" 
		redirectport="8443" relaxedquerychars="\" uriencoding="ISO-8859-1" />

2017年8月4日 星期五

Sublime Text:百家姓切割(每列一姓)

需求:
    由Internet取得百家姓字串,
    想將百家姓儲存到資料庫以供程式搜尋使用,
    因此想將百家姓切割為每列一姓。
環境:
    macOS Sierra (10.12.6)
    Sublime Text 3
方法:
    在Sublime Text軟體中
    點選[FIND] >> [Replace],
    點選[Regular expression]按鈕,
    在[Find What:]中輸入:(.{1})
    在[Eplace With:]中輸入:\1\n
    點選[Replace All]按鈕後就完成了

2017年1月23日 星期一

如何更改session timeout?
1 網站的 session timeout 預設值30 min

2 變更整個網站的 session timeout 值(60 min) 修改web.xml:
  <webapp>
    ...
    <session-config>
      <session-timeout>60</session-timeout> <!-- in minutes -->
    </session-config>
  </webapp>


3 變更單一session timeout 值(60 min) 修改servlet:
getRequest().getSession().setMaxInactiveInterval(3600)

2016年5月17日 星期二

OS X Changing eclipse(Mars) project explorer tree view font size
Open Finder
right mouse click eclipse.app , click 顯示套件內容
open file Eclipse.app/Contents/Eclipse/plugins/org.eclipse.ui.themes_1.1.1.v20151026-1355/css/e4_basestyle.css
There I added :
.MPart Tree {
font-size: 13;
}

2012年11月16日 星期五

Eclipse自動佈屬到Tomcat

先概述一下我的NB開發環境:

(一)安裝JAVA JDK 於 C:\Program Files (x86)\Java\jdk1.6.0_31

(二)解壓縮 Eclipse Juno 於 C:\junoEclipse\eclipse

(三)解壓縮 Tomcat 於 D:\apache-tomcat-7.0.32

(四)Eclipse 設定

  1. 設定 Install JREs:

    Eclipse : Window >> Preferences

    Preferences : Java >> Installed JREs >> Add...

    JRE Type : Standard VM >> Next >

    JRE Definition : JRE home = C:\Program Files (x86)\Java\jdk1.6.0_31, Remove Eclipse JRE >> Finish

  2. 設定 Server Runtime Environments

    Eclipse : Window >> Preferences

    Preferences : Server >> Runtime Environments >> Add...

    New Server Runtime Environment : select Apache Tomcat v7.0, 勾選 Create a new local Server >> Next>

    Tomcat Server : Tomcat Installation directory=D:\apache-tomcat-7.0.32, JRE=jdk1.6.0_31 >> Finish
  3. 設定 Tomcat Server:

    Eclipse : Window >> Show View >> Servers

    Servers : 以滑鼠右鍵點選 Tomcat v7.0 Server as localhost >> Open

    Tomcat v7.0 Server as localhost :

    • Server locations:

      點選 Use Tomcat installation(takes control of Tomcat installation),

      Deploy Path=webapps

    • server Options :

      勾選Publish module contexts to separate XML files,

      勾選Modules auto reload by default,

      關閉Tomcat v7.0 Server視窗,Save Yes

  4. 新增 Dynamic Web Project:

    Eclipse : File >> New >> Dynamic Web Project

    New Dynamic Web Project : Project name=myWeb2, 其他使用預設值 >> Finish

  5. 新增 Hello Html :

    Project Explorer :以滑鼠右鍵點選myWeb2 >> New >> HTML File >> File name=index.html >> Finish

    index.html :在後輸入 Hello ! Html >> File >> Save

  6. 將 Web 專案佈屬到 Tomcat Server:

    Eclipse : Window >> Show View >> Servers

    Servers : 以滑鼠右鍵點選 Tomcat v7.0 Server as localhost >> Start

    Servers : 以滑鼠右鍵點選 Tomcat v7.0 Server as localhost >> Add and Remove...

    Add and Remove : Available: myWeb2 >> Add >> Finish

    Web Browser : 開啟網頁 http://localhost:8080/myWeb2/index.html,如果看到Hello ! Html ,就表示已經成功佈屬到Tomcat Server了!

Eclipse jQuery Error 的解決方法

最近利用Eclipse在學習jQuery,發現當我加入jQuery壓縮檔(jquery-1.8.2.min.js)後,發現會有驗證失敗的小圖示出現,雖然不會影響學習jQuery,但就是不喜歡在專案中出現紅色的小X(如下圖)。

利用Google搜尋後,發現可以設定JavaScript排除驗證以min.js結尾的檔案,來去除惱人的紅色小X,請參考以下設定步驟:

(一)Eclipse的Project Explore中以滑鼠右鍵點選專案後選擇Properties

(二)依序點選:JavaScript >>Include Path>>Source>>Excluded>>Edit...

(三)點選Exclusion patterns下的 Add...按鈕,輸入**/*.min.js (** : 代表所有目錄)後,點選OK按鈕。

最後按下Finish按鈕及OK按鈕(畫面省略)後,就成功移除惱人的紅色小X。