Apache7 与 struts2 + struts2-json-插件 + jquery-ui 自动完成:特殊字符未正确转义
希望你能帮我解决一个问题: 我将 Struts2 与 struts2-json-plugin 一起使用,版本均为 2.1.8.1。 JQuery-UI 的版本是 1.8.9。整个 shebang 运行在 Tomcat 7.0.8 上。 我的问题是这样的:当我在搜索字段中输入特殊字符(例如名称“Müller”)时,将使用参数“müller”调用 struts-action 的 setTerm(String term) 方法。所以,很明显,发生了一些编码错误。
我为自动完成定义了一个源 Struts-Action,它的配置 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>
提前感谢您的帮助!
hope you can help me with a problem:
I use Struts2 with the struts2-json-plugin, both in version 2.1.8.1. The JQuery-UI's version is 1.8.9. The whole shebang runs on Tomcat 7.0.8.
My problem is this: When I enter special characters (for example the name "Müller") into the search field, the method setTerm(String term) of my struts-action is called with parameter "müller". So, clearly, some encoding error occurs.
I defined a source Struts-Action for autocomplete, it's configuration-xml looks like this:
<action name="SearchUsers" class="...">
<interceptor-ref name="..." />
<result type="json">
<param name="root">users</param>
<param name="noCache">true</param>
</result>
</action>
This is how I configured autocomplete on the web page:
<?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>
Thanks in advance for helping!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@toLowerCase我:
我不确定 UTF-8 是否支持这一点,struts2 内部将使用 UTF-8 编码模式作为默认模式。
因此,请检查 UTF-8 是否是原因,如果是的话,请创建一个 struts2.properties 文件并设置类似的编码。
这是我的假设,我根本没有尝试过,所以你所能做的就是玩玩..
@toLowerCase me:
i am not sure if UTF-8 is supporting this or not,internally struts2 will be using UTF-8 encoding schema as default one.
So check if UTF-8 is the cause if it is so create a struts2.properties file and set your encoding something like.
this is my assumption and i have not tried it at all,so all you can do is to play around..
问题隐藏在Tomcat的server.xml中。连接器是这样的:
它缺少 URIEncoding="UTF-8" 属性:
The problem was hidden in Tomcat's server.xml. The Connector was like this:
It was missing a URIEncoding="UTF-8" attribute: