TomCat 8.00とIntelliJ IDEA 14.0とh2データベースを使用しています。データベース内のテキストフィールド(キリル文字)のテキストフィールドからテキストを取得するときは、次のようになります。TomCatでのJSPファイルエンコーディング
これは私のindex.jspのファイル
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
<title>Home</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
これは私のサーブレット
public class RegisterServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("usernameReg");
String pass = request.getParameter("passReg");
String name = request.getParameter("firstNameReg");
String lastName = request.getParameter("lastNameReg");
String email = request.getParameter("emailReg");
request.setAttribute("Username", username);
StudentBean regstudent;
try {
regstudent = new RegisterDAO().registerStudent(username, pass, name, lastName, email);
request.getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
} catch (SQLException e) {
e.printStackTrace();
}
}
と私のRegisterDAOクラスである:
public class RegisterDAO {
Connection conn = null;
PreparedStatement state = null;
//ResultSet res = null;
public StudentBean registerStudent(String userName, String pass, String name, String lastName, String email) throws SQLException{
StudentBean result = null;
String sql = "INSERT INTO STUDENT VALUES(null, ?, ?, ?, ?, ?)";
try {
conn = DbConnection.getInstance().getConnect();
state = conn.prepareStatement(sql);
state.setString(1, userName);
state.setString(2, pass);
state.setString(3, name);
state.setString(4, lastName);
state.setString(5, email);
state.execute();
} catch (SQLException e) {
System.out.println("Нулл поинт");
e.printStackTrace();
}finally {
if(state != null){
state.close();
}
}
DbConnection.getInstance().Disconnect();
return result;
}
}
英語ではすべて正常に動作します。私は、JSPファイルがUTF-8でcorectlyに保存されておらず、デフォルトのIntelliJエンコーディングを使用していると思います。
私は問題を解決するためのアイデアに感謝します。
敬具、 D. Balamjiev
のIntelliJであなたのJSPファイルを開き、右下の隅に取得するかどうか確認する、それはそれはUTF-だファイル –
のエンコーディングでなければなりません8、しかし働いていない。 –
データベースを確認してください。 –