我用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
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
解决方案 »
- 利用jacob将Word转成PDF时候报错:Invoke of: SaveAs
- client端能給jndi服務器綁定屬性嗎
- 页面源文件和实际操作不符。。怎么办
- 关于hibernate的排序问题
- apple标签转变为object的问题
- 关于SSH中数据库连接关闭的疑问
- j2ee ssh 开发办公自动化OA项目 想了解一下相关开发过程中的一些问题100分
- Tomcat 部署项目后只能通过localhost访问的问题!!!!!!
- Spring2.5+Struts2.0+hibernate3 在Tomcat5.5中,启动的时候,老是提示noDefClass,怎么回事呀
- 项目外包:连锁POS系统
- j2ee中,这个页面的效果应该怎样实现?鼠标放在"交易日志"上,下面会出现一个下拉框,如图,鼠标移走自动消失!
- 话说Java与JavaScript
response.setContentType("text/html;charset=UTF-8");