我用out输出流向jsp页面的ajax输出返回值的时候,代码如下:
try {
String retrurnString="";
List<Operator> opList=service.findAllOperator();
for(Operator o : opList){
if(userName.equals(o.getAccount())){
request.put("userRepeat", "用户名重复");
retrurnString="repeat";
break;
}
}
if(!retrurnString.equals("")){
this.readHtml(retrurnString);
return null;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return "error";
}上面的readHtml()封装如下:
protected void readHtml(String data) throws IOException
{
HttpServletResponse response = ServletActionContext.getResponse();
try
{
response.setCharacterEncoding("UTF-8");
response.getWriter().write(data);
} catch (IOException e)
{
e.printStackTrace();
throw e;
}
}以下为jisp代码:  function bSuccess(responseText, statusText, xhr, $form)
        {
        alert(responseText);
         if(responseText=="repeat"){
         $("#userErr").html("用户名重复请重新输入");
         $("#userName").select();
         $("#userName").focus();
         }else{
         alert("保存成功");
         window.returnValue = "1";
         window.close();
         }
        }然后到页面调试的时候, alert(responseText);弹出的字符为<PRE>repeat</PRE>,更奇怪的是我在本机测试可以实现功能,但是访问部署在服务器上的不行,调试弹出<PRE>repeat</PRE>,非常费解,困扰好几个小时,在线求解答,ajax。ssh