当前位置: 代码迷 >> Java Web开发 >> jquery ajax向SSH2传值一定要用json么?该如何处理
  详细解决方案

jquery ajax向SSH2传值一定要用json么?该如何处理

热度:4870   发布时间:2013-02-25 21:21:18.0
jquery ajax向SSH2传值一定要用json么???
想用jquery ajax 做用户注册效果,在验证用户名的时候,不想用json,因为只有一个键值对,没必要用json。但是用text的话,在后台的function中又不知道怎么写,jquery才能获得返回的response。
以前用servlet做的时候直接用的writeOut,现在该怎么写呢???网上找的全是json啊。
js代码如下:
JScript code
                        $.ajax({                            type: "POST",                            url: "http://127.0.0.1:8080/myweb"+inputobj.attr("ajaxurl")+"?"+ new Date().getTime(),                            data: "param="+$(this).val(),                            dataType: "text",                            beforeSend:function(){alert("gogo--");},                            success: function(s){                                if(s=="y"){                                    inputobj.attr("valid","true");                                    $.fn.Validform.sn.showmsg(tipmsg.r,settings.tiptype,{obj:inputobj,type:2},"hide");                                }else{                                    inputobj.attr("valid",s);                                    errorobj=inputobj;                                    $.fn.Validform.sn.showmsg(s,settings.tiptype,{obj:inputobj});                                }


后台的struts2 的function该部分是:

Java code
    /**     * 检查用户昵称是否存在     */    public void checkUserName(){        String nikeName = param;                System.out.println("====================================");        System.out.println(nikeName);        System.out.println("====================================");                if(us.checkName(nikeName)){            System.out.println("=======我知道这里写的不对,但是不知道怎么写,因为是struts2的,struts1还好说==============");            this.setInfor("y");        }else{            this.setInfor("n");        }    }


就是这个function里该怎么写,js才能获得它传的值呢。。。

------解决方案--------------------------------------------------------
和servlet写的一样print出来就行了
------解决方案--------------------------------------------------------
在struts2中也可以取得到response的啊
  相关解决方案