从mysql使用jsp获取无效的hindi字符串 [英] getting invalid hindi string from mysql using jsp
本文介绍了从mysql使用jsp获取无效的hindi字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这里是设置
这次使用odbc连接
![显示设置] [1]
[1]:http://i.stack.imgur.com/4f2bD.jpg
和
! utf8 here] [1]
[1]:http://i.stack.imgur.com/C9fo5.jpg
这里是我的代码
<% -
文档:index.jsp
创建日期:2011年8月30日,10:57:05 AM
作者:Sahil
- %>
<%@ page contentType =text / htmlpageEncoding =UTF-8import =java.sql。*;%>
<%@ page import =java.util。*%>
<%@ page import =java.io。*%>
<%@ page import =java.lang.RuntimePermission%>
<!DOCTYPE html>
< html>
< head>
< title>旁遮普语 - 印地语字典|输出< / title>
< link href =style.css =stylesheettype =text / cssmedia =screen/>
< / head>
< body>
< form accept-charset =UTF-8>
<%
try
{
if(request.getCharacterEncoding()== null)
request.setCharacterEncoding(UTF-8) ;
Connection cn;
语句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>
这次它给了我不同的输出
स¾¤¤¾à¤¹à¤¿¤¤²
स¾¤¤³à¹¹¤¿解决方案$ /
>
显然,您的输出是单页编码(例如ISO-8859-1),而不是UTF-8,这可能有几个原因:
- 您检查数据是否正确存储在数据库中?如果没有,您应该检查用于存储数据的表是否为UTF-8
-
您的数据库连接是否正确设置为使用UTF-8?我不知道如何这样做odbc,但对于mysql-jdbc驱动程序,您可能需要将它附加到您的配置url:
characterEncoding = utf-8
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
साहिल
साहिलसाहिल
解决方案
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
这篇关于从mysql使用jsp获取无效的hindi字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文