getting invalid hindi string from mysql using jsp

点点圈 提交于 2019-12-13 09:35:36

问题


here are the settings

this time using odbc connection

![showing u the settings][1]


[1]: http://i.stack.imgur.com/4f2bD.jpg

and

![ i have mentioned utf8 here][1]


[1]: http://i.stack.imgur.com/C9fo5.jpg

here is my code


<%-- 
Document   : index.jsp
Created on : 30 Aug, 2011, 10:57:05 AM
Author     : Sahil
--%>
<%@page contentType="text/html" pageEncoding="UTF-8" import = "java.sql.*;"%>
<%@page import = "java.util.*"%>
<%@ page import = "java.io.*"%> 
<%@page import= "java.lang.RuntimePermission" %>
<!DOCTYPE html>
<html>
<head>
 <title>Punjabi-Hindi Dictionary | Output</title>
 <link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body>
  <form accept-charset="UTF-8">  
    <%

    try
      { 
       if (request.getCharacterEncoding() == null) 
           request.setCharacterEncoding("UTF-8");
       Connection cn;

       Statement st;
       ResultSet rs;
       Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       cn=DriverManager.getConnection("jdbc:odbc:myodbc","root","");
       st=cn.createStatement();   
       rs=st.executeQuery("select * from stu_info");
       while(rs.next()){
       String Name= rs.getString("Name");

     %> 
     <%=Name%>
     <br>
      <%
                        }
     rs.close();
     st.close();
     cn.close();
     }
     catch(Exception ex)
     {
      out.println(ex.getMessage());
     }
      %>

    </form>    
    </body>
  </html>

  this time it gives me diffrent output

  साहिल
  साहिलसाहिल 

回答1:


Obviously your output is in a single page encoding (e.g. ISO-8859-1) and not in UTF-8, this can have several reasons:

  • Have you checked the data is correctly stored in your database? If not, you should check if the table you use for storing the data is UTF-8
  • Is your database connection properly set up to use UTF-8? I don't know how this is done for odbc, but for the mysql-jdbc Driver you might need to append this to your configuration url:

    characterEncoding=utf-8



来源:https://stackoverflow.com/questions/7333601/getting-invalid-hindi-string-from-mysql-using-jsp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!