PrintWriter out = null;
try {
out=response.getWriter();
} catch (IOException e) {
e.printStackTrace();
out.print("error");
}
···········
out.print("请重新输入!");
return;
也可以有其他方式的操作,比如
PrintWriter out = null;
Gson gson = new Gson();
try {
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
out.print(gson.toJson("error"));
}
if (("").equals(haha) || null == haha){
out.print(gson.toJson("不能为空!"));
return;
}
String msg = "{\"flag\":\"success\"}";
前台的解析
$.ajax({
type:"POST",
url:"${requestContext.baseHref}xxx.html" + param,
dataType:"json",
success:function(msg){
if(msg!='error'){
if('success'==msg.flag){
}else{
alert(msg);
}
}else{
alert("请求出错");
}
},
error:function(msg){
alert("请求出错");
}
});