【问题标题】:Apache7 with struts2 + struts2-json-plugin + jquery-ui autocomplete: Special characters not escaped properly带有struts2 + struts2-json-plugin + jquery-ui自动完成的Apache7:特殊字符未正确转义
【发布时间】:2011-03-31 07:29:41
【问题描述】:

希望你能帮我解决一个问题: 我在 2.1.8.1 版本中使用带有 struts2-json-plugin 的 Struts2。 JQuery-UI 的版本是 1.8.9。整个 shebang 在 Tomcat 7.0.8 上运行。 我的问题是这样的:当我在搜索字段中输入特殊字符(例如名称“Müller”)时,我的 struts-action 的方法 setTerm(String term) 使用参数“müller”调用。所以,很明显,发生了一些编码错误。

我为自动完成定义了一个源 Struts-Action,它的 configuration-xml 看起来像这样:

<action name="SearchUsers" class="...">
    <interceptor-ref name="..." />
    <result type="json">
        <param name="root">users</param>
            <param name="noCache">true</param>
    </result>
</action>

这是我在网页上配置自动完成的方式:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript" src="jquery-ui/jquery-1.4.4.min.js"></script>
    <link rel="stylesheet" type="text/css" href="jquery-ui/css/ui-lightness/jquery.ui.all.css" />
    <script type="text/javascript" src="jquery-ui/jquery-ui-1.8.9.custom.min.js"></script>
    <script type="text/javascript">
        $("#nachname").autocomplete({
            source : "SearchUsers.action",
            dataType : "json",
            minLength : 3
        });
    </script>
</head>
<body>...</body>
</html>

提前感谢您的帮助!

【问题讨论】:

    标签: json struts2 jquery-ui-autocomplete


    【解决方案1】:

    @toLowerCase 我: 我不确定 UTF-8 是否支持这一点,内部 struts2 将使用 UTF-8 编码模式作为默认模式。 因此,请检查 UTF-8 是否是原因,如果是这样,请创建一个 struts2.properties 文件并设置类似的编码。

    ### This can be used to set your default locale and encoding scheme
    # struts.locale=en_US
    struts.i18n.encoding=UTF-8
    

    这是我的假设,我根本没有尝试过,所以你所能做的就是玩弄..

    【讨论】:

    • 很遗憾,这已经在我的 struts.properties 文件中设置了。仍然:非常感谢您尝试帮助我解决这个问题! :-)
    • 我们在我们的应用程序中使用了简单的主题并且它工作正常你可以尝试在你的struts2无线电标签中设置them=simple来看看发生了什么吗?
    • 我使用
    【解决方案2】:

    问题隐藏在 Tomcat 的 server.xml 中。连接器是这样的:

    <Connector connectionTimeout="20000" port="8888" protocol="HTTP/1.1" redirectPort="8443"/>
    

    缺少 URIEncoding="UTF-8" 属性:

    <Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8888" protocol="HTTP/1.1" redirectPort="8443"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-18
      • 2020-02-11
      • 1970-01-01
      • 1970-01-01
      • 2014-02-08
      • 2017-02-08
      相关资源
      最近更新 更多