<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=Big5">
<title>測試劉覽器 URL 編碼</title>
</head>
<body>
<h2>測試劉覽器 URL 編碼</h2>
<h3>HTML 以 Big5 編碼,呼叫 EchoBig5</h3>
<form method="GET" action="/xml/servlet/EchoBig5">
<input type="text" value="老呂" name="data">
<input type="submit" value="確定">
</form>
</body>
</html>
讀者可以到
01 import javax.servlet.*;
02 import javax.servlet.http.*;
03 import java.io.*;
04
05 public class EchoBig5 extends HttpServlet {
06 public void doGet(HttpServletRequest req, HttpServletResponse res)
07 throws ServletException, IOException {
08 PrintWriter output;
09
10 res.setContentType("text/html;charset=Big5");
11 output = res.getWriter();
12
13 StringBuffer buf = new StringBuffer();
14 buf.append("<html><head><title>\n");
15 buf.append("Echo Big5\n");
16 buf.append("</title></head><body>\n");
17
18 String data = req.getParameter("data");
19 String orig = data.length() + " ";
20 for(int i=0; i<data.length(); i++) {
21 int ch = (int)data.charAt(i);
22 orig = orig + "%" + Integer.toHexString(ch);
23 }
24 String out1 = new String(data.getBytes("ISO-8859-1"), "Big5");
25
26 buf.append("<h1>String: " + data + "</h1>\n");
27 buf.append("<h1>Hex Numbers: " + orig + "</h1>\n");
28 buf.append("<h1>Big5 Encoded: " + out1 + "</h1>\n");
29 buf.append("</body></html>\n");
30 output.println(buf.toString());
31
32 output.close();
33 }
34 }
EchoBig5 類別是一個 Java servlet,不清楚的讀者可以參考