我正在用两种语言(英语和法语)制作表格。当有人输入它的名字时,表单使用 ajax 从我们的数据库中查询信息。可悲的是,当我使用 response.getWriter().write("Hey é è"); 功能它似乎不支持像'é''è'这样的字符。
这是我的 javascript 和 ajax :
function fillBlanks(idOfInputText,valueOfInputText)
{
//Prepare a new ajaxRequest.
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//Ajax receiving the response in this function
xmlhttp.onreadystatechange = function()
{
//state 4 is response ready.
//Status 200 is page found.
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
//Change the content of the select to ajax result.
var content = [];
content = decode(xmlhttp.responseText);
document.getElementById('lastName').innerHTML = content[0];
document.getElementById('firstName').innerHTML = content[1];
document.getElementById('defaultPrinter').innerHTML = content[2];
document.getElementById('dropDownRespExistant').innerHTML = content[3];
}
};
//Send the Ajax request.
xmlhttp.open('GET','mainServlet?command=ajax.FillBlanksHtml&ID='+ idOfInputText + '&VALUE=' + valueOfInputText, true);
xmlhttp.send();
}
这是我的java类:
public class FillBlanksHtmlCommand extends FrontCommand
{
public static String userName;
public static String lastName;
public static String firstName;
@Override
public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
{
String value = new String(request.getParameter("VALUE"));//get the ajax value
response.getWriter().write(OracleUserFinder.findHtmlCodeForOracleUser(value));
}
}
我想知道是否可以通过其他方式发送特殊字符。如果你能告诉我这个函数使用什么编码,那就太好了!!