當我從JSP頁面中的表單提交EUR(€)符號到Servlet時,我得到一個額外的2個隨機字符。 (我的IDE是IntelliJ)。爲什麼提交了其他兩個角色,並且有什麼我失蹤?在表單中提交歐元符號並獲取額外的2個字符
我在JSP頁面的格式如下:
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="utf-8" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Euro Form</title>
</head>
<body>
<form action="/servlet" method="post">
<input type="text" name="txtInput1" value="">
<button type="submit">Submit</button>
</form>
</body>
</html>
這是由以下的Servlet處理:
package servlets;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(name = "Servlet", urlPatterns = {"/servlet"})
public class Servlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
request.getRequestDispatcher("/WEB-INF/jsp/form.jsp").include(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String txtInput1 = request.getParameter("txtInput1");
char[] chars = txtInput1.toCharArray();
// ...
request.setAttribute("txtInput1", txtInput1);
request.getRequestDispatcher("/WEB-INF/jsp/form.jsp").include(request, response);
}
}
當我從表格提交歐元(€)符號Servlet,我收到一個隨機的字符集3,實際上,如下所示,但是當我將其打印回HTML頁面時,它顯示爲€符號...:
這似乎是與一個unicode翻譯http://utf8-chartable.de/unicode-utf8-table.pl?start=8320&number=128&names=-&utf8=dec – Christian
很好閱讀https://www.joelonsoftware.com/2003/10/08/the-絕對最低限度 - 每個軟件開發人員 - 絕對肯定 - 必須知道 - 關於unicode和字符集 - 無藉口/ – Christian