gpt4 book ai didi

java - 如何使用 XPAGES DesignerFacesServlet 显示泰语字母(以及另一个亚洲/阿拉伯字母)

转载 作者:行者123 更新时间:2023-12-01 19:39:14 27 4
gpt4 key购买 nike

我尝试创建 XSP Servlet,并希望在我的 Web 应用程序中完全支持泰语(和/或其他亚洲/阿拉伯字母)。

此脚本是来自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();

刚刚对泰语和阿拉伯语进行了快速测试,这似乎有效。

关于java - 如何使用 XPAGES DesignerFacesServlet 显示泰语字母(以及另一个亚洲/阿拉伯字母),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55912578/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com