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れたインターセプターではなく、 1 つの のみを使用しています。

それらを次のように変更します。

<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 に答える