西里尔文输入检索为Mojibake

时间:2015-05-09 14:17:01

标签: jsf primefaces character-encoding cyrillic

我正在使用PrimeFaces和postgresql开发Web应用程序。

我有一些与数据库相关的表单。该项目需要使用西里尔字符。因此,当我在文本字段中填写一些字符时,西里尔字母就可以了,但是当我单击按钮并重新加载表单时,我会看到一些垃圾字符。

我使用tomcat作为服务器,我正在我的计算机上本地开发应用程序。

这是我的faces-config.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<faces-config
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
    version="2.2">
 <application>
      <message-bundle>
        bg_messages
      </message-bundle>
      <locale-config>
        <default-locale>bg_BG</default-locale>
        <supported-locale>bg</supported-locale>
      </locale-config>

     </application>
</faces-config>

在xhtml页面上我有

<?xml version="1.0" encoding="UTF-8"?>

数据库没问题,因为当我尝试手动添加一些西里尔字符时,它们正在工作。我在其中一个页面中也有一些自动完成功能,当我在数据库中手动添加西里尔文的一些数据然后尝试自动完成时它工作正常。

以下是我的一个页面:

<h:body>
    <h1>Вход</h1>
    <h:form>

        <h:outputText value="Потребителско име: " />
        <p:inputText value="#{USER.username}" />

        <br />
        <br />
        <h:outputText value="Парола: " />
        <p:password id="nonFeedback" value="#{USER.password}" />

        <br />
        <br />


        <h:commandButton value="Вход" action="#{USER.login}" target="_self" />



    </h:form>

</h:body>

所以当我把一些西里尔文数据放入

<p:inputText value="#{USER.username}" />

然后单击按钮我得到垃圾奇怪的字符。这与我的注册表格相同。当我将数据填入表单并再次提交时,会显示奇怪的字符,并将它们存储在数据库中而不是真正的正确数据中。

这是我的注册表格:

<?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://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<h:head>

 <title>Home | E-Shopper</title>
    <h:outputStylesheet library="css" name="bootstrap.min.css" />
    <h:outputStylesheet library="css" name="font-awesome.min.css" />
    <h:outputStylesheet library="css" name="prettyPhoto.css" />
    <h:outputStylesheet library="css" name="price-range.css" />
    <h:outputStylesheet library="css" name="animate.css" />
    <h:outputStylesheet library="css" name="main.css" />
    <h:outputStylesheet library="css" name="responsive.css" />



    <h:outputScript library="js" name="bootstrap.min.js" />
    <h:outputScript library="js" name="jquery.scrollUp.min.js" />
    <h:outputScript library="js" name="price-range.js" />
    <h:outputScript library="js" name="jquery.prettyPhoto.js" />
    <h:outputScript library="js" name="main.js" />






    <h:link rel="shortcut icon" href="images/ico/favicon.ico"></h:link>
   <h:link rel="apple-touch-icon-precomposed" sizes="144x144" href="images/ico/apple-touch-icon-144-precomposed.png"></h:link>
   <h:link rel="apple-touch-icon-precomposed" sizes="114x114" href="images/ico/apple-touch-icon-114-precomposed.png"></h:link>
    <h:link rel="apple-touch-icon-precomposed" sizes="72x72" href="images/ico/apple-touch-icon-72-precomposed.png"></h:link>
   <h:link rel="apple-touch-icon-precomposed" href="images/ico/apple-touch-icon-57-precomposed.png"></h:link>



</h:head>
<h:body>

<div id="main_container_reg">

    <h1 class="reg_title">Регистрация</h1>


 <h:form>



<h:outputLabel styleClass="labels_reg" for="name" value="Име:  " />
<p:inputText styleClass="fields_reg" id="name" value="#{USER.name}"/>
<br/><br/>

<h:outputLabel styleClass="labels_reg" for="lastname" value="Фамилия:  " />
<p:inputText styleClass="fields_reg" id="lastname" value="#{USER.surname}" />
<br/><br/>
<h:outputLabel styleClass="labels_reg" for="username" value="Потребителско име: * " />
<p:inputText styleClass="fields_reg" id="username" required="true" value="#{USER.username}"  />


    <h:panelGrid styleClass="pass_reg" columns="2" id="matchGrid" >                  
        <h:outputLabel styleClass="labels_reg" for="password" value="Парола: *" />
        <p:password styleClass="fields_reg" id="password" match="pass_conf" label="Парола" required="true" value="#{USER.password}" />

        <h:outputLabel styleClass="labels_reg" for="pass_conf" value="Потвърди парола: *" />
        <p:password styleClass="fields_reg" id="pass_conf" value="EditorBean" label="полето за потвърждение" required="true" />
    </h:panelGrid>

 <br/>
<h:outputLabel styleClass="labels_reg" for="email" value="Електронна поща: * " />
<p:inputText styleClass="fields_reg" id="email" required="true" value="#{USER.email}" />
 <br/><br/>
<h:outputLabel styleClass="labels_reg" for="phone" value="Телефон: " />
<p:inputText styleClass="fields_reg" id="phone" value="#{USER.phone}"  />


<h:panelGrid styleClass="user_type" columns="2" style="margin-bottom:10px" >
        <p:outputLabel  value="Тип потребител" />
        <br/>
   <p:selectOneRadio id="data" binding="#{yesOrNo}" required="true" value="No">
   <f:selectItem itemValue="No"  itemLabel="Частно Лице" />
   <f:selectItem itemValue="Yes" itemLabel="Фирма" />
   <p:ajax update="campany_name" />
   <p:ajax update="city" />
   <p:ajax update="street" /> 
   <p:ajax update="street_number" />
   <p:ajax update="zip" />
    <p:ajax update="upload" />
</p:selectOneRadio>

    </h:panelGrid>


<h:outputLabel styleClass="labels_reg" for="company_name" value="Име на фирма: "  />
<p:inputText styleClass="fields_reg" value="#{USER.companyName}"  id="campany_name" disabled="#{yesOrNo.value != 'Yes'}" />
 <br/> <br/>

<h3 style="margin:0 0 0 15px;">Адрес: </h3>
<br/>
<h:outputLabel  styleClass="labels_reg" for="city" value="Град: "  />
<p:inputText styleClass="fields_reg" value="#{USER.city}" id="city" disabled="#{yesOrNo.value != 'Yes'}" />
<br/><br/>
<h:outputLabel styleClass="labels_reg" for="street" value="Улица: "  />
<p:inputText styleClass="fields_reg" value="#{USER.street}" id="street" disabled="#{yesOrNo.value != 'Yes'}" />
<br/><br/>
<h:outputLabel styleClass="labels_reg" for="street_number" value="Номер на Улица: "  />
<p:inputText styleClass="fields_reg" value="#{USER.streetNumber}"  id="street_number" disabled="#{yesOrNo.value != 'Yes'}" />
<br/><br/>
<h:outputLabel styleClass="labels_reg" for="zip" value="Пощенски код: "  />
<p:inputText styleClass="fields_reg" value="#{USER.zip}" id="zip" disabled="#{yesOrNo.value != 'Yes'}" />

<br/> <br/>

<p:messages id="messages" showDetail="true" autoUpdate="true" />
        <p:fileUpload fileUploadListener="#{USER.getImageURL}"
            allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="100000"
            description="Select Images" disabled="#{yesOrNo.value != 'Yes'}"
            id="upload" />

        <br />
        <br />
        <h:form enctype="multipart/form-data">
            <p:growl id="messages" showDetail="true" />





            <p:commandButton styleClass="reg_button"  action="#{USER.addUser}" value="Регистрация" ajax="false"
                disabled="false" />
            <br />
            <br />
        </h:form>

    </h:form>

</div>


</h:body>
</html>

0 个答案:

没有答案