如何使用 XPAGES DesignerFacesServlet 显示泰文字母(和另一个 Asian/Arabic 字母)
How to display Thai letter (and another Asian/Arabic letter) using XPAGES DesignerFacesServlet
我已尝试创建 XSP Servlet,并希望在我的 Web 应用程序中完全支持泰语(和/或其他 Asian/Arabic 字母)。
此脚本是 https://frostillic.us/blog/posts/159496067A27FD3585257A70005E7BC1
的自定义版本
环境:Domino 9.0.1 FP6,Windows Server 2008
package com.testing.servlet;
import java.io.*;
import java.util.*;
import com.ibm.commons.util.StringUtil;
import com.ibm.xsp.webapp.DesignerFacesServlet;
import javax.faces.context.FacesContext;
import javax.servlet.*;
import javax.servlet.http.*;
import lotus.domino.*;
public class Testing extends DesignerFacesServlet {
//Session
private static Session getCurrentSession(FacesContext context) {
return (Session) context.getApplication().getVariableResolver()
.resolveVariable(context, "session");
}
private void incinerate(Object... dominoObjects) {
for (Object dominoObject : dominoObjects) {
if (null != dominoObject) {
if (dominoObject instanceof Base) {
try {
((Base)dominoObject).recycle();
} catch (NotesException e) {
System.out.println("[FAILED TO RECYCLE]");
e.printStackTrace();
}
}
}
}
}
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest)servletRequest;
HttpServletResponse res = (HttpServletResponse)servletResponse;
ServletOutputStream out = res.getOutputStream();
FacesContext facesContext = this.getFacesContext(req, res);
Session session = null;
Database database = null;
View view = null;
Document doc = null;
try {
session = getCurrentSession(facesContext);
database = session.getCurrentDatabase();
view = database.getView("lkBehavior");
doc = view.getDocumentByKey("pBehavior");
res.setContentType("text/plain");
res.setCharacterEncoding("utf-8");
out.println("start");
Map<Object, Object> sessionScope = facesContext.getExternalContext().getSessionMap();
sessionScope.put("counter", sessionScope.containsKey("counter") ? (Integer)sessionScope.get("counter") + 1 : 1);
out.println("Counter: " + sessionScope.get("counter"));
Map<String, String[]> param = req.getParameterMap();
for(String key : param.keySet()) {
out.println(key + " => " + StringUtil.concatStrings(param.get(key), ';', false));
}
out.println(doc.getItemValueString("values")); // field values contains thai letter
out.println("done");
} catch(Exception e) {
e.printStackTrace(new PrintStream(out));
} finally {
out.close();
incinerate(doc,view,database,session);
if(facesContext!=null){
facesContext.responseComplete();
facesContext.release();
}
}
}
}
结果
start
Counter: 5
???????????? // thai letter display as ????
done
如何显示泰文字母而不是 ????
我在处理挪威字符时遇到了类似的问题。能够通过切换到 PrintWriter
而不是 ServletOutputStream
:
来修复它
HttpServletResponse res = (HttpServletResponse) servletResponse;
HttpServletRequest req = (HttpServletRequest) servletRequest;
res.setContentType("application/json; charset=UTF-8;");
//use a PrintWriter here, since we also have to deal with UTF-8 characters
PrintWriter out = res.getWriter();
刚刚对泰语和阿拉伯语进行了快速测试,这似乎有效。
我已尝试创建 XSP Servlet,并希望在我的 Web 应用程序中完全支持泰语(和/或其他 Asian/Arabic 字母)。
此脚本是 https://frostillic.us/blog/posts/159496067A27FD3585257A70005E7BC1
的自定义版本环境:Domino 9.0.1 FP6,Windows Server 2008
package com.testing.servlet;
import java.io.*;
import java.util.*;
import com.ibm.commons.util.StringUtil;
import com.ibm.xsp.webapp.DesignerFacesServlet;
import javax.faces.context.FacesContext;
import javax.servlet.*;
import javax.servlet.http.*;
import lotus.domino.*;
public class Testing extends DesignerFacesServlet {
//Session
private static Session getCurrentSession(FacesContext context) {
return (Session) context.getApplication().getVariableResolver()
.resolveVariable(context, "session");
}
private void incinerate(Object... dominoObjects) {
for (Object dominoObject : dominoObjects) {
if (null != dominoObject) {
if (dominoObject instanceof Base) {
try {
((Base)dominoObject).recycle();
} catch (NotesException e) {
System.out.println("[FAILED TO RECYCLE]");
e.printStackTrace();
}
}
}
}
}
public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest)servletRequest;
HttpServletResponse res = (HttpServletResponse)servletResponse;
ServletOutputStream out = res.getOutputStream();
FacesContext facesContext = this.getFacesContext(req, res);
Session session = null;
Database database = null;
View view = null;
Document doc = null;
try {
session = getCurrentSession(facesContext);
database = session.getCurrentDatabase();
view = database.getView("lkBehavior");
doc = view.getDocumentByKey("pBehavior");
res.setContentType("text/plain");
res.setCharacterEncoding("utf-8");
out.println("start");
Map<Object, Object> sessionScope = facesContext.getExternalContext().getSessionMap();
sessionScope.put("counter", sessionScope.containsKey("counter") ? (Integer)sessionScope.get("counter") + 1 : 1);
out.println("Counter: " + sessionScope.get("counter"));
Map<String, String[]> param = req.getParameterMap();
for(String key : param.keySet()) {
out.println(key + " => " + StringUtil.concatStrings(param.get(key), ';', false));
}
out.println(doc.getItemValueString("values")); // field values contains thai letter
out.println("done");
} catch(Exception e) {
e.printStackTrace(new PrintStream(out));
} finally {
out.close();
incinerate(doc,view,database,session);
if(facesContext!=null){
facesContext.responseComplete();
facesContext.release();
}
}
}
}
结果
start
Counter: 5
???????????? // thai letter display as ????
done
如何显示泰文字母而不是 ????
我在处理挪威字符时遇到了类似的问题。能够通过切换到 PrintWriter
而不是 ServletOutputStream
:
HttpServletResponse res = (HttpServletResponse) servletResponse;
HttpServletRequest req = (HttpServletRequest) servletRequest;
res.setContentType("application/json; charset=UTF-8;");
//use a PrintWriter here, since we also have to deal with UTF-8 characters
PrintWriter out = res.getWriter();
刚刚对泰语和阿拉伯语进行了快速测试,这似乎有效。