JSF UTF-8个字符没有看到只在第一个表单后,JSF,tomcat的?(JSF UTF 8 ch

2019-10-18 03:56发布

我有一个简单的JSF表单,我提交的用户名和密码,并坚持到数据库。

只有在第一种形式提交,我有UTF-8字符的问题。 当我在第一篇文章提交ğğüüçç,我得到错误的字符。 在第二次尝试,这是正常的。

这是我的web.xml和的index.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">

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



    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>

</web-app>

我的index.xhtml:

<!DOCTYPE html>
<html lang="tr"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">
<h:head>
    <title>Title</title>
</h:head>
<h:body>
    <div class="container">
        <h:form styleClass="form-signin" prependId="false" id="registirationForm">
            <h2 class="form-signin-heading">Please Register!</h2>
            <h:inputText styleClass="input-block-level" value="#{registirationFormBean.nickname}" />
            <h:inputSecret styleClass="input-block-level" value="#{registirationFormBean.password}"/>
            <h:commandButton styleClass="btn btn-large btn-primary" value="Register Me!" action="#{registirationFormBean.registerUser}"/>
        </h:form>
    </div>
</h:body>
</html>

编辑:这是在Tomcat中的server.xml

 <Connector port="8080" maxHttpHeaderSize="8192"
               maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="20000" disableUploadTimeout="true"
               URIEncoding="UTF-8"
   />

当我调试我的应用程序,在第一篇文章我看值贴:

但在第二时间:

Answer 1:

采用

<f:view>

和你的语言环境。

    <f:view locale="#{registirationFormBean.locale}" encoding="UTF-8" contentType="text/html"> 
<h:head>
    <title>Title</title>
</h:head>
<h:body>
    <div class="container">
        <h:form styleClass="form-signin" prependId="false" id="registirationForm">
            <h2 class="form-signin-heading">Please Register!</h2>
            <h:inputText styleClass="input-block-level" value="#{registirationFormBean.nickname}" />
            <h:inputSecret styleClass="input-block-level" value="#{registirationFormBean.password}"/>
            <h:commandButton styleClass="btn btn-large btn-primary" value="Register Me!" action="#{registirationFormBean.registerUser}"/>
        </h:form>
    </div>
</h:body>

</f:view>

从你喜欢的bean提供Locale对象。

public Locale getLocale(){
return new Locale("tr", "TR");
}


文章来源: JSF UTF 8 characters not seen ONLY in first form post, jsf, tomcat?
标签: jsf tomcat utf-8