【发布时间】:2014-11-11 12:46:37
【问题描述】:
我使用下面的jsp来搜索一些文本:
<%@page session="false" contentType="text/html; charset=utf-8" %>
..
...
<form method="post" action="searchPageAction.html">
<input type="text" name="search_value" value="ö-Test"/>
</form>
...
Servlet 如下所示:
public class SearchServlet {
private static final String SEARCH_VALUE = "search_value";
@Override
protected final void doPost(final SlingHttpServletRequest request, final SlingHttpServletResponse response) throws ServletException {
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
String searchValue = request.getParameter(SEARCH_VALUE);
String redirectPath = "/content/vrbp/de/tools/suchergebnis.html?q="+searchValue+"&_charset_=UTF-8";
try {
response.setCharacterEncoding("UTF-8");
response.sendRedirect(redirectPath);
} catch (IOException e) {
} catch (IllegalStateException e) {
}
}
}
现在当我搜索“ö-Test”时,浏览器中写入了以下链接:
http://www.testproject:4502/content/myProject/searchResult.html?q=%F6-Test&charset=UTF-8
我已经预料到了:
http://www.testproject:4502/content/myProject/searchResult.html?q=ö-Test&字符集=UTF-8
并且将 searchResult.html 中的文本 ö-Test 打印为 &#65533;-Test。如何在UTF-8 中正确编码?我做错了什么?
【问题讨论】:
标签: jsp servlets encoding character-encoding aem