In my Liferay
portlet app where I use Spring MVC
framework, is something wrong with the encoding and I can't figure out what. According to the firebug logs, the value leaves frontend encoded well. But after it's passed to backend's action handler, the encoding is ambiguous.
For example:
In the frontend is the value: "abcčdďeěf". But to backend arrives "abc─Źd─Će─Ťf".
My form:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="portlet" uri="http://java.sun.com/portlet_2_0" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<portlet:defineObjects />
<portlet:actionURL var="formUrl" name="sendForm"/>
<% request.setCharacterEncoding("UTF-8"); %>
<form name="editForm"
method="POST"
action="${formUrl}"
>
<input type="text" name="query" id="query"/>
<input value="Submit" type="submit" />
</form>
<br>
Action handler:
@ActionMapping(value = "sendForm")
public void sendForm(ActionRequest request, ActionResponse response, Model model) throws UnsupportedEncodingException {
String query = request.getParameter("query");
/*
* Here is the value of query already ambiguous
*/
if (query != null && (query.matches(".*\\w.*"))) {
ArrayList<SearchResultEntity> searchResutls = solrSearchService.getSearchResults("http://localhost:8983/solr/GE/select?q=content%3A" + query + "+OR+title%3A" + query + "+OR+id%3A" + query + "&wt=json&indent=true");
System.out.println("http://localhost:8983/solr/GE/select?q=content%3A" + query + "+OR+title%3A" + query + "+OR+id%3A" + query + "&wt=json&indent=true");
request.setAttribute("searchResutls", searchResutls);
}
}
Any idea, how to fix this encoding issue?