日期:2014-05-20  浏览次数:20741 次

Struts2 AJAX --- return返回值疑问。。
使用AJAX之后~ 异步获取数据

Struts2 Action配置
Java code

@Action(value="isexsit",results=@Result(location="/WEB-INF/page/user/checkuser.jsp"))
    public String isExsit(){
        exsit = buyerService.exsit(buyer.getUsername().trim()) == true ? 1 : 0;        
        return SUCCESS;
    }





checkuser.jsp 页面
HTML code

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/page/share/taglib.jsp" %>
<% 
response.setHeader("Cache-Control", "no-store"); //HTTP1.1
response.setHeader("Pragma", "no-cache"); //HTTP1.0
response.setDateHeader("Expires", 0);
%>
<s:if test="exsit">
    <font color="red">red:<s:property value="exsit"/></font>
</s:if>
<s:else>
    <font color="green">green:<s:property value="exsit"/></font>
</s:else>



之后我ajax返回之后。。。 
控制台打印了3次查询

liming7
Hibernate: select count(buyer0_.username) as col_0_0_ from Buyer buyer0_ where buyer0_.username=? limit ?
liming7
Hibernate: select count(buyer0_.username) as col_0_0_ from Buyer buyer0_ where buyer0_.username=? limit ?
liming7
Hibernate: select count(buyer0_.username) as col_0_0_ from Buyer buyer0_ where buyer0_.username=? limit ?

页面的返回结果为

green:success 

无论我输入什么。。Ajax返回的结果都是 success ,

这个该如何解决?

------解决方案--------------------
struts2 都可以这样配置了啊 好久没有弄过了
换一个jquery( ajax框架)用一下
------解决方案--------------------
没怎么看懂。。buyerService.exsit(buyer.getUsername().trim()) == true ? 1 : 0; 这是个三目运算。 ajax的代码 没贴出来!! 说明白点
------解决方案--------------------
你这个必须都返回success
判断一下,1返回success,0返回error
------解决方案--------------------
其实注解不好,难维护!