我正在尝试使用jersey 2.13 API + TOMCAT 7创建一个安静的Web服务。我的目的是在我的计算机上显示目录和文件作为响应。
除土耳其编码外,一切正常。我的HTML回复包括土耳其字符。我做了所有事情(添加; charset = ISO-8859-9到注释,添加了charset的元素,在响应头添加了charset,在响应头添加了语言等)但是我的页面仍然充满了未知的字符而不是土耳其人。
由于我的低代表,我无法发布显示问题的图像。 :S 相反,这是我服务器响应的链接
<a href="http://localhost:8080/TezWebServer/rest/servis/klasor?ad=C://**Görüntü Ä°ÅLEME GENEL">KLASOR:Görüntü Ä°ÅLEME GENEL**</a>
这个应该是
<a href="http://localhost:8080/TezWebServer/rest/servis/klasor?ad=C://**GÖRÜNTÜ İŞLEME GENEL">KLASOR:GÖRÜNTÜ İŞLEME GENEL</a>
相同的代码使用jersey 1x正常工作我认为这是一个错误:S
@GET
@Path("klasor")
@Produces(MediaType.TEXT_HTML+";charset=ISO-8859-9")
public Response dosyalariGosterHTML(@QueryParam("ad") String klasorAdi){
if(klasorAdi==null||klasorAdi.equals("")){
klasorAdi = "C:/";
}
StringBuffer sb = new StringBuffer();
sb.append("<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
<html><head><meta http-equiv='Content-Type' content='text/html; charset=ISO-8859-9'/>
<META HTTP-EQUIV='Content-language' CONTENT='tr'><title>Tez İD</title></head><body>");
try{
klasorAdi = text_convert_ters(klasorAdi);
File folder = new File(klasorAdi);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
sb.append("<a href='http://localhost:8080/TezWebServer/rest/servis/dosya?adres="+klasorAdi+"/"+ listOfFiles[i].getName()+"'>DOSYA:"+listOfFiles[i].getName()+"</a><br/>");
} else if (listOfFiles[i].isDirectory()) {
sb.append("<a href='http://localhost:8080/TezWebServer/rest/servis/klasor?ad="+klasorAdi+"/"+ listOfFiles[i].getName()+"'>KLASOR:"+listOfFiles[i].getName()+"</a><br/>");
}
}
sb.append("</body></html>");
}catch(Exception e){
e.printStackTrace();
sb.append("Hata:Belirtilen Yol Geçersiz</body></html>");
}
return Response.ok(sb.toString()).language(Locale.getDefault()).header("charset", "ISO-8859-9").build();
}
public String text_convert_ters(String eskiStr)
{
String yeniStr = "";
for(int index = 0; index < eskiStr.length(); index++)
{
char tmpStr = eskiStr.charAt(index);
if(tmpStr == '\360') tmpStr='ğ';
else if(tmpStr == '\320') tmpStr='Ğ';
else if(tmpStr == '\375') tmpStr='ı';
else if(tmpStr == '\335') tmpStr='İ';
else if(tmpStr == '\366') tmpStr='ö';
else if(tmpStr == '\326') tmpStr='Ö';
else if(tmpStr == '\374') tmpStr='ü';
else if(tmpStr == '\334') tmpStr='Ü';
else if(tmpStr == '\376') tmpStr='ş';
else if(tmpStr == '\336') tmpStr='Ş';
else if(tmpStr == '\347') tmpStr='ç';
else if(tmpStr == '\307') tmpStr='Ç';
yeniStr = yeniStr + tmpStr;
}
return yeniStr;
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>TezWebServer</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>/axis2-web/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>benim.tez.projem.rs.servis</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet>
<display-name>Apache-Axis Servlet</display-name>
<servlet-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/servlet/AxisServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>*.jws</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>