我有一个移动应用程序,它的rest Api是使用eclipse用Jakarta EE编写的,数据库是oracle,当然,我们将war文件上传到apache服务器上,用于实时应用程序,我们为此使用的apache服务器版本是tomcat apache V8.5。当我们在使用本地服务器时通过应用程序插入数据时,阿拉伯语文本可以正常工作,并在Oracle中正确显示。但是当我们上传war文件并通过tomcat apache使用live应用程序时,阿拉伯语文本就不起作用了。我使用了几个选项,但没有得到正确的结果。我还尝试在server.xml文件中的连接器内部设置uriencoding=“utf-8”,但它不起作用。
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--><!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
--><Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<!-- Prevent memory leaks due to use of particular java/javax APIs-->
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" maxHttpHeaderSize="65536" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log" suffix=".txt"/>
<Context docBase="JobVisit" path="/JobVisit" reloadable="true" source="org.eclipse.jst.jee.server:JobVisit"/></Host>
</Engine>
</Service>
</Server>
但是,当我试图在eclipse中将字符串转换为UTF-8时,不知何故,它可以工作,但有些字母表并不合适,因为“”显示为“??”。
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import org.codehaus.jettison.json.JSONArray;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import com.google.gson.Gson;
import com.rest.database.DBConnection;
@Path("/arabicTest")
public class MaintenanceRequestRegistrationTest {
@SuppressWarnings({ "unchecked" })
@POST
@Path("arabic")
@Produces("application/json")
@Consumes("application/json")
public String crunchifycreateKCM(InputStream incomingData) throws JSONException {
Connection dbConnection = null;
Statement stmt = null;
// JSONArray myArray = new JSONArray();
JSONObject jsarr = new JSONObject();
try {
// con.setAutoCommit(false);
dbConnection = DBConnection.getDBConnection();
dbConnection.setAutoCommit(false);
stmt = (Statement) dbConnection.createStatement();
// System.out.println("Iam entering try catch bloxck");
new Gson();
InputStream in = incomingData;
String a = convertStreamToString(in);
// System.out.println(a);
JSONObject json = new JSONObject(a);
JSONArray kcm = json.getJSONArray("createkcm");
// System.out.println("length of json data"+kcm.length());
// updating kcmd data
JSONObject jo = kcm.getJSONObject(0);
String cmremarks = jo.getString("cmremarks");
cmremarks = new String(cmremarks.getBytes(),"UTF-8");
String sqlQuery3 = "insert into test(COL1) values('"+ cmremarks + "')";
int count = stmt.executeUpdate(sqlQuery3);
if(count>0) {
jsarr.put("status", "200");
}else {
jsarr.put("status", "100");
}
dbConnection.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
// db connection close 16-Nov
try {
if (stmt != null)
stmt.close();
if (dbConnection != null)
dbConnection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// return HTTP response 200 in case of success
// return Response.status(200).entity(ret.toString()).build();
System.out.print(jsarr.toString());
return jsarr.toString();
}
private String convertStreamToString(InputStream is) {
/*
* To convert the InputStream to String we use the BufferedReader.readLine()
* method. We iterate until the BufferedReader return null which means there's
* no more data to read. Each line will appended to a StringBuilder and returned
* as String.
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}
所以请任何人指导我如何解决这个问题,我还附上了我的server.xml和java类rest Api代码
根据@piotrp.karwasz的建议,我使用了双参数InputStreamReader构造函数,它工作了
private String convertStreamToString(InputStream is) {
/*
* To convert the InputStream to String we use the BufferedReader.readLine()
* method. We iterate until the BufferedReader return null which means there's
* no more data to read. Each line will appended to a StringBuilder and returned
* as String.
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
问题内容: 我正在评估NLTK处理阿拉伯文本的能力,这项研究旨在分析和提取情感。 问题如下: NTLK是否可以处理并允许分析阿拉伯文本? python是否能够操纵\标记阿拉伯文本? 我可以使用Python解析和存储阿拉伯文本吗? 如果python和NTLK不是完成这项工作的工具,那么您会推荐哪些工具(如果存在)? 谢谢。 编辑 根据研究: NTLK仅能阻止阿拉伯文本:链接 Python支持UTF-
我正在尝试使用最新的雅虎天气apihttps://weather-ydn-yql.media.yahoo.com/forecastrss它工作得很好,但当我设置语言(lang=ar AE)时,它返回带问号的json响应,而不是阿拉伯字符。例如“城市”:“城市”对于英语来说,这是可以的。 我没看到留档里有关于utf设置的东西 当我打开雅虎的天气页面https://www.yahoo.com/news
Adobe 亚洲语言书写器 借助 Adobe 亚洲语言书写器,您可以使用中东和南亚语言创建内容。您可以键入或混合键入阿拉伯语、希伯来语、英语和其他语言。 您可以在“段落”面板菜单(窗口 > 段落 > 面板菜单)中的可用书写器之间进行选择。例如,您可以使用中东和南亚语言单行书写器或中东和南亚语言逐行书写器。 有关 Illustrator 中支持的其他亚洲语言的更多信息,请参阅适用于亚洲语言文字的书写
启用中东语言功能 若要在 Photoshop 界面中显示中东文字选项,请执行以下操作: 选取“编辑”>“首选项”>“文字”(Windows) 或“Photoshop”>“首选项”>“文字”(Mac OS)。 在“选取文本引擎选项”部分中,选取“中东”。 单击“确定”,并重新启动 Photoshop。 选取“文字”>“语言选项”>“中东语言功能”。 文本方向 要创建阿拉伯语和希伯来语内容,您可以将默
问题内容: 我有一个要排序的阿拉伯语单词列表。我曾尝试使用不同的语言环境(例如英语或法语,但希望不高)使用标准的Collator,甚至创建了自己的RuleBasedCollator,但无济于事。显然,默认排序依赖于unicode值顺序,该顺序在许多情况下都有效,但显然不适用于此顺序。 按照javadocs的说明,RuleBasedCollator需要一个字符串,该字符串以您希望它们排序
我有一个关于阿拉伯语编码和将阿拉伯语存储到mysql的问题。 我应用了以下所有步骤: set-MySQL字符集:UTF-8 Unicode(utf8) 设置MySQL连接排序规则:utf8\u常规\u ci 集合数据库和表排序规则设置为:utf8\U general\U ci或utf8\U unicode\U ci mysql_查询(“设置名称‘utf8’”); mysql_查询('SET CHA