webService 使用Ajax提交的问题

ajax请求代码:

 <script>
    var xhr = new XMLHttpRequest();
    function wsConnection(){
        //创建XMLHttp的对象

        //服务的地址
        var urlMsg = 'http://192.168.1.174:6789/hello';

        //请求体
        var soap = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:q0="http://score.it.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema'+        'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><q0:sayHello> <arg0>aaa</arg0> <arg1>123</arg1></q0:sayHello></soapenv:Body> </soapenv:Envelope>';

        //打开连接-true :表示为异步请求
        xhr.open('POST',urlMsg,true);     
        xhr.crossDomain=true;   

        //重新设置头信息
        xhr.setRequestHeader("Content-Type","text/xml;charset=utf-8");   

        //设置回调函数
        xhr.onreadystatechange=_back;

        //发送请求
        xhr.send(soap);
    }

    function _back(){
        if(xhr.readyState==4){
            if(xhr.status==200){
                alert('成功响应');
                var ret = xhr.responseXML;
                var msg = ret.getElementsByTagName("return")[0];
                alert(msg.text)
            }
        }
    }
</script>
<body>
    <input type="button" value="发送请求" onclick="wsConnection()"/>
    <input type="text" id="response"/>
</body>

主程序与控制台输出代码:

 @WebService
public class HelloService {

    public String sayHello(String name,int num){
        System.out.println("客户请求来了..................");
        return "Hello "+name;
    }

    //发布时,此方法不显示
    @WebMethod(exclude=true)
    public String sayHi(String name){
        return "Hi "+name;
    }

    public static void main(String[] args) {
        /**
         * 参数1:服务发布地址
         * 参数2:服务实现者
         */
        Endpoint.publish("http://192.168.1.174:6789/hello", new HelloService());
        System.out.println("我是由主线程执行");
    }

}

控制台:
五月 29, 2015 9:30:06 上午 com.sun.xml.ws.transport.http.server.WSHttpHandler handleExchange
警告: 无法处理 HTTP 方法: OPTIONS

补充:ajax提交后所示:![图片说明](https://img-ask.csdn.net/upload/201505/29/1432863066_123052.png)图片说明

你ajax请求的的地址跨域了(端口不一致也算,除非你用的ie)。请求跨域地址时,ajax先用option方法请求你的这个地址获取Access-Control-Allow-Origin响应头是否包含请求域名或者为*允许跨域,如果不允许会报跨域错误

你的控制台输出这个错误是因为你服务器无法处理option方法请求,自己找下java如何配置允许option请求