Java portlet请求中的UTF-8编码

Java portlet请求中的UTF-8编码,java,spring,forms,utf-8,liferay,Java,Spring,Forms,Utf 8,Liferay,在我使用的springmvcframework的Liferayportlet应用程序中,编码有问题,我不知道是什么。根据firebug日志,该值使前端编码良好。但在将其传递给后端的操作处理程序后,编码是不明确的。 例如: 前端是值:“abcčdďeěf”。但对“abc”来说─Źd─Će─Ťf” 我的表格: <?xml version="1.0" encoding="UTF-8" ?> <%@ page language="java" contentType="text/html

在我使用的
springmvc
framework的
Liferay
portlet应用程序中,编码有问题,我不知道是什么。根据firebug日志,该值使前端编码良好。但在将其传递给后端的操作处理程序后,编码是不明确的。 例如: 前端是值:“abcčdďeěf”。但对“abc”来说─Źd─Će─Ťf”

我的表格:

<?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>


操作处理程序:

@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);
        }
    }
@ActionMapping(value=“sendForm”)
public void sendForm(ActionRequest请求、ActionResponse响应、模型模型)引发不支持的DencodingException{
字符串查询=request.getParameter(“查询”);
/*
*下面是已经不明确的查询值
*/
if(query!=null&(query.matches(.*\\w.*)){
ArrayList SearchResultls=solrSearchService.getSearchResults(“http://localhost:8983/solr/GE/select?q=content%3A“+query+”+或+title%3A“+query+”+或+id%3A“+query+”&wt=json&indent=true”);
System.out.println(“http://localhost:8983/solr/GE/select?q=content%3A“+query+”+或+title%3A“+query+”+或+id%3A“+query+”&wt=json&indent=true”);
setAttribute(“searchResultls”,searchResultls);
}
}
你知道如何解决这个编码问题吗?

试试看

request.setCharacterEncoding("UTF-8"); 
以前

 request.setAttribute("searchResutls", searchResutls);

这不会有帮助…var
查询的编码不明确。我需要在
solrSearchService.getSearchResults(“http://localhost:8983/solr/GE/ …
向另一台服务器发送请求
query.matches(“.*\\w.”)
谢谢您的建议。检查是否只有空格的最佳方法可能是myString.trim().isEmpty()