Chapter 7 Form and request l request implicit

  • Slides: 23
Download presentation
Chapter 7 Form and request

Chapter 7 Form and request

資料的取得 l request 隱含物件(implicit object-不需宣告可 直接使用) – javax. servlet. http. Http. Servelet. Request request.

資料的取得 l request 隱含物件(implicit object-不需宣告可 直接使用) – javax. servlet. http. Http. Servelet. Request request. get. Parameter(“控制項名稱”); 注意雙引號

如何使用get方法傳遞中文 試試看: <a href=response. jsp? tbx. Name=<%=“徐煥智”%>> 將<%=“徐煥智”%>改為 <%=java. net. URLEncoder. encode(“徐煥智”, ”utf-8”)%> To

如何使用get方法傳遞中文 試試看: <a href=response. jsp? tbx. Name=<%=“徐煥智”%>> 將<%=“徐煥智”%>改為 <%=java. net. URLEncoder. encode(“徐煥智”, ”utf-8”)%> To convert a String, each character is examined in turn: • The ASCII characters 'a' through 'z', 'A' through 'Z', and '0' through '9' remain the same. • The space character ' ' is converted into a plus sign '+'. • All other characters are converted into the 3 -character string "%xy", where xy is the twodigit hexadecimal representation of the lower 8 -bits of the character.

如何使用get方法傳遞中文 l 如何解碼 String keyword = new String(request. get. Parameter("keyword"). get. Bytes("iso-8859 -1"), "utf-8");

如何使用get方法傳遞中文 l 如何解碼 String keyword = new String(request. get. Parameter("keyword"). get. Bytes("iso-8859 -1"), "utf-8"); public byte[] get. Bytes(String charset. Name) Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array. public String(byte[] bytes, String charset. Name) Constructs a new String by decoding the specified array of bytes using the specified charset.

Post 方法中文傳遞 request. set. Character. Encoding("big 5");

Post 方法中文傳遞 request. set. Character. Encoding("big 5");

修改server. xml <Connector port="8080" max. Threads="150" min. Spare. Threads="25" max. Spare. Threads="75" enable. Lookups="false"

修改server. xml <Connector port="8080" max. Threads="150" min. Spare. Threads="25" max. Spare. Threads="75" enable. Lookups="false" redirect. Port="8443" accept. Count="100" debug="0" connection. Timeout="20000" disable. Upload. Timeout="true" URIEncoding="MS 950". . . 新增

資料型別的轉換 l String (表單傳遞的資料型別) 轉為數值 型別類別 Integer. parse. Int(String 字串) Float. parse. Float(String 字串)

資料型別的轉換 l String (表單傳遞的資料型別) 轉為數值 型別類別 Integer. parse. Int(String 字串) Float. parse. Float(String 字串) Double. parse. Double(String 字串) Boolean. value. Of(String 字串) “true” -> true otherwise ->false

控制項的建立與訊息傳遞 l 核取方塊 傳出 on <input type=“checkbox”name=“核取方塊名稱 1”checked> <input type=“checkbox”name=“核取方塊名稱 2”> 傳出 null <%

控制項的建立與訊息傳遞 l 核取方塊 傳出 on <input type=“checkbox”name=“核取方塊名稱 1”checked> <input type=“checkbox”name=“核取方塊名稱 2”> 傳出 null <% do not suggest if (request. get. Parameter(“核取方塊名稱”). equals(“on”)) {. . . } %> <% if (request. get. Parameter(“核取方塊名稱”) != null) {. . . } %>