我的页面中有一些文本框,用户可以在其中编辑他的信息。这是该文件的代码:
<?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:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h1>Kişisel Bilgileri Değiştir</h1>
<h:panelGrid columns="4" >
<h:outputText value="Kullanıcı Adı: "></h:outputText>
<h:inputText style=" background-color: #DCDAD1; " id="tUserName" readonly="true" value="#{user.customer.username}" />
<h:outputText style="color: red" value="*Kullanıcı adı değiştirilemez" ></h:outputText>
<h:outputText></h:outputText>
<h:outputText id="tPassword" value="Şifre: "></h:outputText>
<h:inputText id="passwordInputText" required="true"
requiredMessage="*Şifre bilgisi zorunludur"
value="#{user.customer.password}" />
<h:outputText></h:outputText><h:outputText></h:outputText>
<h:outputText id="tName" value="Ad: "></h:outputText>
<h:inputText id="nameInputText" required="true"
requiredMessage="*İsim bilgisi zorunludur"
value="#{user.customer.name}" />
<h:outputText></h:outputText>
<h:outputText></h:outputText>
<h:outputText id="tSurName" value="Soyad: "></h:outputText>
<h:inputText id="surnameInputText" required="true"
requiredMessage="*Soyad bilgisi zorunludur"
value="#{user.customer.surname}" />
<h:outputText></h:outputText><h:outputText></h:outputText>
<h:outputText id="tPhone" value="Telefon: "></h:outputText>
<h:inputText id="phoneInputText" required="true"
requiredMessage="*Telefon bilgisi zorunludur"
value="#{user.customer.phone}" />
<!-- validatorMessage="*Örnek:+902123475671">
<f:validateRegex pattern=
"\+[0-9]{12}" />
</h:inputText>-->
<h:outputText></h:outputText>
<h:outputText id="tAddress" value="Adres: "></h:outputText>
<h:inputTextarea rows="5" id="addressInputText" value="#{user.customer.address}" />
<h:outputText></h:outputText><h:outputText></h:outputText>
<h:outputText id="tEmail" value="E-mail: "></h:outputText>
<h:inputText id="emailInputText" required="true"
requiredMessage="*E-mail bilgisi zorunludur"
value="#{user.customer.email}"
validatorMessage="*E-mail formatı yanlış">
<f:validateRegex pattern=
"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />
</h:inputText>
<h:outputText></h:outputText><h:outputText></h:outputText>
<h:commandButton value="Onayla" action="#{user.editInfo()}">
</h:commandButton>
</h:panelGrid>
</h:form>
</h:body>
</html>
我使用 phpmyadmin 和 mysql。这是我的桌子:
但是当我在文本框中输入一些像 Ö,Ç,İ,Ğ,Ü,Ş 这样的字符并更新数据库时,我会得到奇怪的字符,例如 Ã?Ä?İıÅ?Å?Ã?çÃ?一个¶。我怎样才能解决这个问题?我尝试将 utf8_bin 和 utf8turkish_ci 作为排序规则,但它不起作用。任何人都可以帮忙吗?
谢谢
编辑:这是我用新用户输入编辑我的数据库的地方:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package classes;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
/**
*
* @author SUUSER
*/
@ManagedBean(name = "user")
@SessionScoped
public class User implements Serializable {
public static Customer customer;
private Connection con=null;
public void setCustomer(Customer customer) {
User.customer = customer;
}
public Customer getCustomer() {
return customer;
}
public User() {
}
public void editInfo() {
String name = customer.getName(), surname = customer.getSurname(), password = customer.getPassword();
String phone = customer.getPhone(), address = customer.getAddress(), email = customer.getEmail();
try {
con=DBConnect.connect();
int result = -1;
PreparedStatement checkDB = (PreparedStatement) con.prepareStatement(
"UPDATE users set password=?,name=?,surname=?,phone=?,address=?,"
+ "email=? where username=?");
checkDB.setString(7, customer.getUsername());
checkDB.setString(1, password);
checkDB.setString(2, name);
checkDB.setString(3, surname);
checkDB.setString(4, phone);
checkDB.setString(5, address);
checkDB.setString(6, email);
result = checkDB.executeUpdate();
con.close();
FacesContext.getCurrentInstance().getExternalContext().redirect("editsuccesfull.xhtml");
} catch (Exception e) {
e.printStackTrace();
}
}
}