2

我有脚本代码:

<script type="text/javascript" >

     var xmlHttp=null;
    function GetXmlHttpObject()
    {

        try
        {
            // Firefox, Opera 8.0+, Safari
            xmlHttp=new XMLHttpRequest();
        }
        catch (e)
        {
            //Internet Explorer
            try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
        }
        return xmlHttp;
    }
    function popSubCategory(){
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        {
            alert ("Browser does not support HTTP Request")
            return;
        }



        var url="<%= request.getContextPath()%>/populatePropertySubCategory.action";
          alert(url);


        xmlHttp.onreadystatechange=stateChangedmp();
        xmlHttp.open("POST",url,true);
        xmlHttp.send(null);
    }
    function stateChangedmp(){

        alert("Hello "+xmlHttp.readyState);
        if(xmlHttp.readyState==4)
        alert("lk"+xmlHttp.responseText);
    }
</script>

我的Action方法是

public String populatePropertySubCategory() {
        System.out.println("sub property called " );

        String errorXml = "This is a Sample to Check";

        response.setContentType("text/html");
        response.setHeader("Cache-Control", "no-cache");
        try {
            response.getWriter().write(errorXml);
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }

        return SUCCESS;

    }

我的动作支持 xml 是

 <action name="populatePropertySubCategory" method="populatePropertySubCategory" class="PropActionSupport">
            <interceptor-ref name="validation">
            <param name="excludeMethods">populatePropertySubCategory</param>
        </interceptor-ref>
        <result name="success" type="tiles" >
           submitProperty
            </result>
        </action>

现在,当我调用此代码时,警报仅 0 并且不打印响应文本。

我已经实现了ServletResonseAware接口。

4

2 回答 2

1

只需尝试更改 javascript 方法

xmlHttp.onreadystatechange=stateChangedmp();  

xmlHttp.onreadystatechange=function myFun {stateChangedmp();}
于 2013-02-08T11:45:27.753 回答
0

class属性需要类的完整限定名,包括包。

而且您只使用一个Interceptor,而不是所有堆栈加上自定义的Validation拦截器;

将它们更改为:

<action name="populatePropertySubCategory" 
        method="populatePropertySubCategory"
        class="org.foo.bar.PropActionSupport">

     <interceptor-ref name="defaultStack">
         <param name="validation.excludeMethods">
            populatePropertySubCategory
         </param>
     </interceptor-ref>

     <result name="success" type="tiles" >submitProperty</result>
</action>

PS:这是最明显的问题,但可能是 javascript 和结果图块部分中的其他问题:&

于 2013-01-31T09:17:25.073 回答