[英]Tomcat 8 utf-8 configuration on netbeans 8.1 not working
When I write data from my index.xhtml input field into database, I get ??? 当我将index.xhtml输入字段中的数据写入数据库时,我得到了??? instead of ąčę.
而不是±čę。 I have set my database Collation to utf8_general_ci.
我已将数据库排序规则设置为utf8_general_ci。 I printed out my value and in Tomcat 8 output i already see ???
我打印出了我的值,并且在Tomcat 8输出中我已经看到了? so I guess it's tomcats problem.
所以我想这是雄猫的问题。 I have checked out a lot of guides and other stackoverflow questions/solutions, nothing helped.
我已经检查了很多指南和其他stackoverflow问题/解决方案,没有任何帮助。 This is what i have done:In tomcats server.xml i have:
这是我所做的:在tomcats server.xml中,我有:
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="8084" protocol="HTTP/1.1" redirectPort="8443"/>
In tomcats web.xml i uncommented 在tomcats web.xml中,我未注释
<filter>
<filter-name>setCharacterEncodingFilter</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<async-supported>true</async-supported>
</filter>
and 和
<filter-mapping>
<filter-name>setCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
In netbeans project web.xml i have 在netbeans项目web.xml中,我有
<filter>
<filter-name>setCharacterEncodingFilter</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
This is my filter setCharacterEncodingFilter.java 这是我的过滤器setCharacterEncodingFilter.java
package Servlets;
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;
public class setCharacterEncodingFilter implements Filter {
@Override
public void init(FilterConfig filterConfig)
throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
servletRequest.setCharacterEncoding("UTF-8");
servletResponse.setContentType("text/html; charset=UTF-8");
filterChain.doFilter(servletRequest, servletResponse);
}
@Override
public void destroy() {
}
}
in index.xtml i have all code covered 在index.xtml中,我已经覆盖了所有代码
<f:view contentType="text/html" encoding="UTF-8">
<h:head>
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
</h:head>
*code*
</f:view>
This is all i could do after reading all problems solving and guides, have i done something wrong? 阅读完所有问题解决方案和指南后,这就是我所能做的,我做错了什么吗?
I got the answer. 我得到了答案。 I edited -&useEncoding=true&characterEncoding=UTF-8-
我编辑了-&useEncoding = true&characterEncoding = UTF-8-
<property name="javax.persistence.jdbc.url" value="jdbc:mysql:url?zeroDateTimeBehavior=convertToNull&useEncoding=true&characterEncoding=UTF-8"/>
and it got fixed 它固定了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.