我在使用ap:commandbutton.when在p:commandButton中更新值时出现问题,我设置ajax =“true”所有事情都没问题,但是当我设置ajax =“false”时,p:inputText中的值不编码,在下一页显示我ÙرÛÙ。或者发送到mysql数据库时。 我正在使用Filter,但我的问题无法解决。
请帮助我 感谢
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui">
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<p:inputText value="#{bean.name}" />
<p:commandButton value="check" ajax="false" action="page2"/>
</h:form>
</h:body>
</html>
答案 0 :(得分:2)
我应该使用Filter来解决这个问题。
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>myengineer.EncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
和java类过滤器
package myengineer;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
/**
*
* @author alfa
*/
public class EncodingFilter implements Filter{
///===================================================================================
public void init(FilterConfig config) throws ServletException {
//No-op
}
///===================================================================================
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);
}
///==================================================================================
public void destroy() {
//No-op
}
///===================================================================================
}