jsp - Post 使用 unicode(希伯来字母)的请求未正确显示

jsp - Post request with unicode (hebrew letters) not showing correctly

我正在尝试使用 jsp 来传递使用 post 的表单,其中数据填充有希伯来字母。

我不知道如何解决。我只想让文字正常显示。我的代码:(代码在名为 newgame.jsp 的 jsp 文件中)

<form id="creategame" action="newgame.jsp" method="post">
    //Form containing a bunch of inputs which can have hebrew outputs
</form>

我收到的输入:

<%
if(request.getParameter("gamename")!=null){
    String gameName = (String)request.getParameter("gamename");
    String minKita = (String)request.getParameter("minkita");
    String maxKita = (String)request.getParameter("maxkita");
    String gameDesc = (String)request.getParameter("gamedesc");
    String gameZiood = (String)request.getParameter("gameziood");
    System.out.println(gameName+" - "+minKita+" - "+maxKita+" - "+gameDesc+" - "+gameZiood);
    //Upload it to the database...
    response.sendRedirect("gamesdb.jsp");
}
%>

基本上:

אבגדהוזחטיכלמנסעפצקרשת turns into ?????????????????????? in the console and àáâãäåæçèéëìîðñòôö÷øùú in the database/website. But, after printing the character data in the console of the "question marks" I can see it's actually àáâãäåæçèéëìîðñòôö÷øùú and not just a bunch of question marks.

那么我如何在我的 post 请求中传递数据以使其保持原始文本?

提前致谢,NonameSL。


编辑: 我正在使用编码 windows-1255,我知道它可以正确显示希伯来字母。


编辑 2: 我尝试使用以下内容:

public String toHebrewString(Object o){
        try{
            return new String(((byte[])o), "UTF-8");
        }catch(Exception unexpected){
            return (String)o;
        }
    }

这显示了完全相同的结果。问题可能出在我的表单上吗?

看到字符串 "א" 包含一个整数值为 224 的字符,下面出错了:

  • Windows 上的希伯来语 single-byte 编码是 Windows-1255(byte)224א.

  • 由于 String/char 应该保存 Unicode 文本,字节到字符串的转换出错了。

  • 检查:

    request.setCharacterEncoding("Windows-1255"); // Once at request begin
    String gameName = request.getParameter("gamename");
    ...
    

    然而,您不希望对每个正在处理的返回表单重复此操作。

  • 解决方案:如果这是一个纯希伯来语站点,您可以使用 Windows-1255,但编码为 UTF-8 的完整 Unicode 是比较平常。如何以UTF-8格式呈现HTML表单,从返回的表单数据中接受UTF-8等等,都可以在网上找到。

响应编码也很关心。还有就是数据库等等。