I use the following jsp to search some text:
<%@page session="false" contentType="text/html; charset=utf-8" %>
..
...
<form method="post" action="searchPageAction.html">
<input type="text" name="search_value" value="ö-Test"/>
</form>
...
the Servlet looks like this:
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) {
}
}
}
Now when I search for example for "ö-Test", The following link is written in the browser:
http://www.testproject:4502/content/myProject/searchResult.html?q=%F6-Test&charset=UTF-8
I have expected:
http://www.testproject:4502/content/myProject/searchResult.html?q=ö-Test&charset=UTF-8
and the text ö-Test
ist printet in searchResult.html as �-Test
. How to encode correct in UTF-8
? What did I do wrong?